to find the program of matrix multiplication using arrays

Answers were Sorted based on User's Feedback



to find the program of matrix multiplication using arrays..

Answer / rohit v.kamlakar

/* Program for matrix multiplication using 2D array
9/20/08
By:-
rohit.born2code@gamil.com or
rohit_kamlakar@rediff.com

*/

#include<iostream.h>
#include<conio.h>
const size=10;
void main()
{
int a[size][size],b[size][size],c[size][size],n,m,i,j,k;
char v;
clrscr();
do
{
m=n=3;
cout<<"Enter a 3X3 matrix(1)\n";

for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
cout<<"Enter a 3X3 matrix(2)\n";

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

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

cout<<"The product matrix is :"<<endl;

for(i=0;i<m;i++)
{
cout<<endl;
for(j=0;j<n;j++)
{
cout<<c[i][j]<<"\t";
}
}
cout<<"\nWanna do it again ? (y/n)";
cin>>v;
}
while(v=='y'||v=='Y');
getch();
}

Is This Answer Correct ?    62 Yes 33 No

to find the program of matrix multiplication using arrays..

Answer / brajesh kumar dwivedi

#include<iostream.h>
#include<conio.h>
const size=10;
void main()
{
int a[size][size],b[size][size],c[size][size],n,m,i,j,k;
char v;
clrscr();
do
{
m=n=3;
cout<<"Enter a 3X3 matrix(1)\n";

for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
cout<<"Enter a 3X3 matrix(2)\n";

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

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

cout<<"The product matrix is :"<<endl;

for(i=0;i<m;i++)
{
cout<<endl;
for(j=0;j<n;j++)
{
cout<<c[i][j]<<"\t";
}
}
cout<<"\nWanna do it again ? (y/n)";
cin>>v;
}
while(v=='y'||v=='Y');
getch();
}

Is This Answer Correct ?    39 Yes 26 No

to find the program of matrix multiplication using arrays..

Answer / suman kumar das.

//matrix multiplication program
#include<stdio.h>
#include<conio.h>

void main()
{
clrscr();
int i,j,k,a[3][3],b[3][3],c[3][3],sum,m=3,l=3;

printf("\n enter value of first matrix:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf("%d",&a[i][j]);
}
printf("\n enter value of second matrix:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf("%d",&b[i][j]);
}
for(i=0;i<m;i++)
{
for(j=0;j<l;j++)
{
c[i][j]=0;
for(k=0;k<l;k++)
c[i][j]+=a[i][k]*b[k][j];
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf("%d",c[i][j]);
}
getch();

}

Is This Answer Correct ?    24 Yes 14 No

to find the program of matrix multiplication using arrays..

Answer / annapurna gautam

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[2][2],b[2][2],c[2][2],i,j;
cout<<"ENTER THE ELEMENT OF FIRST MATRIX"<<"\n";
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
cin>>a[i][j];
}
}
cout<<" THE FIRST MATRIX IS :"<<"\n";
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
cout<<a[i][j]<<"\t";
}
cout<<"\n";
}
cout<<"ENTER THE ELEMENT OF SECOND MATRIX IS "<<"\n";
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
cin>>b[i][j];
}
}
cout<<"THE SECOND MATRIX IS:"<<"\n";
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
cout<<b[i][j]<<"\t";
}
cout<<"\n";
}
cout<<"THE MATRIX IS:"<<"\n";
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
c[i][j]=0;
for(int k=1;k<=2;k++)
{
c[i][j]=c[i][j]+(a[i][k] * b[k][j]);
}
}
}
cout<<"THE MULTIPLICATION OF THE MATRIX IS:"<<"\n";
for(i=1;i<=2;i++)
{
cout<<"\n";
for(j=1;j<=2;j++)
{
cout<<c[i][j]<<"\t";
}
cout<<"\n";
}

getch();

Is This Answer Correct ?    13 Yes 7 No

to find the program of matrix multiplication using arrays..

Answer / mani prakesh

#include<stdio.h>
#include<conio.h>
main()
{
int i,j,r1,c1,r2,c2,m1[2][2],m2[2][2],k,mult[2][2];
printf("Enter rows and columns of first matrix \n");
printf("Again row wise\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
scanf("%d",&m1[i][j]);
}
printf("You have entered the first matrix as follows:\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
printf("%d\t",m1[i][j]);
printf("\n");
}
printf("Enter rows and columns of Second matrix \n");
printf("Again row wise\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
scanf("%d",&m2[i][j]);
}
printf("You have entered the second matrix as
follows:\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
printf("%d\t",m2[i][j]);
printf("\n");
}


// Matrix Multiplication

if(r2==c1)
{
printf("Now we multiply both the above matrix \n");
printf("The result of the multiplication is as
follows:\n");
/*a11xA11+a12xA21+a13xA31 a11xA12+a12xA22+a13xA32
a11xA13+a12xA23+a13xA33*/
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
mult[i][j]=0;
for(k=0;k<r1;k++)
{
mult[i][j]+=m1[i][k]*m2[k][j];

/*mult[0][0]=m1[0][0]*m2[0][0]+m1[0][1]*m2[1][0]+m1[0][2]*m2[2][0];*/
}
printf("%d\t",mult[i][j]);
}
printf("\n");
}

}
else
{
printf("Matrix multiplication cannot be done");
}
getch();
}

Is This Answer Correct ?    4 Yes 1 No

to find the program of matrix multiplication using arrays..

Answer / nikhil verma

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[2][2],b[2][2],c[2][2],i,j;
cout<<"ENTER THE ELEMENT OF FIRST MATRIX"<<"\n";
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
cin>>a[i][j];
}
}
cout<<" THE FIRST MATRIX IS :"<<"\n";
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
cout<<a[i][j]<<"\t";
}
cout<<"\n";
}
cout<<"ENTER THE ELEMENT OF SECOND MATRIX IS "<<"\n";
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
cin>>b[i][j];
}
}
cout<<"THE SECOND MATRIX IS:"<<"\n";
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
cout<<b[i][j]<<"\t";
}
cout<<"\n";
}
cout<<"THE MATRIX IS:"<<"\n";
for(i=1;i<=2;i++)
{
for(j=1;j<=2;j++)
{
c[i][j]=0;
for(int k=1;k<=2;k++)
{
c[i][j]=c[i][j]+(a[i][k] * b[k][j]);
}
}
}
cout<<"THE MULTIPLICATION OF THE MATRIX IS:"<<"\n";
for(i=1;i<=2;i++)
{
cout<<"\n";
for(j=1;j<=2;j++)
{
cout<<c[i][j]<<"\t";
}
cout<<"\n";
}

getch();

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

Write a program to input the price of 1 burger and the number of burgers eaten by a group of friends .print the total amount to be paid by the group?

0 Answers  


What is scope of variable in c?

0 Answers  


#define f(g,h) g##h main O int i=0 int var=100 ; print f ("%d"f(var,10));} wat would be the output??

0 Answers  


Why doesn't the code "a[i] = i++;" work?

4 Answers  


what is the coding of display the factorial of a number using array and function?

1 Answers  






what is the size of an integer variable?

4 Answers  


#include show(int t,va_list ptr1) { int a,x,i; a=va_arg(ptr1,int) printf(" %d",a) } display(char) { int x; listptr; va_star(otr,s); n=va_arg(ptr,int); show(x,ptr); } main() { display("hello",4,12,13,14,44); }

0 Answers   Wilco,


What are keywords c?

0 Answers  


What is the maximum length of an identifier?

0 Answers  


Write c-code for 5+55+555+5555+55555+555555+5555555. Output will be it's answer...

4 Answers   TCS,


How can I read a binary data file properly?

0 Answers  


how to find turn around time in operating system?

3 Answers  


Categories