Pages

Showing posts with label two. Show all posts
Showing posts with label two. Show all posts

Wednesday, February 18, 2015

C Program to do Addition subtraction and multiplication of two numbers using function

C++ Program to do Addition,subtraction and multiplication of two numbers using function

#include<iostream.h>
#include<conio.h>

int res;
void main()
{
clrscr();
int sum(int,int);
int sub(int,int);
int mul(int,int);
int a,b,m,su,s;
cout<<"Enter two numbers:";
cin>>a>>b;

s=sum(a,b);
su=sub(a,b);
m=mul(a,b);
cout<<"Sum:"<<s<<"
Subtraction:"<<su<<"
Multiplication:"<<m;

getch();
}

sum(int a,int b)
{
res=a+b;
return(res);
}

sub(int a,int b)
{
res=a-b;
return(res);
}

mul(int a,int b)
{
res=a*b;
return(res);
}
Read more »

Tuesday, February 17, 2015

C program to multiply two matrices

C++ program to multiply two matrices

#include<iostream.h>
#include<conio.h>


void main()
{
clrscr();
int a[5][5],b[5][5],c[5][5],m,n,p,q,i,j,k;
cout<<"Enter rows and columns of first matrix:";
cin>>m>>n;
cout<<"Enter rows and columns of second matrix:";
cin>>p>>q;

if(n==p)
{
cout<<"
Enter first matrix:
";

for(i=0;i<m;++i)
for(j=0;j<n;++j)
cin>>a[i][j];

cout<<"
Enter second matrix:
";

for(i=0;i<p;++i)
for(j=0;j<q;++j)
cin>>b[i][j];
cout<<"
The new matrix is:
";


for(i=0;i<m;++i)
{
for(j=0;j<q;++j)
{
c[i][j]=0;
for(k=0;k<n;++k)
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
cout<<c[i][j]<<" ";
}
cout<<"
";

}
}
else
cout<<"
Sorry!!!! Matrix multiplication cant be done";

getch();
}
Read more »