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 programe print the sum of series 0,1,2,.....10

7 Answers  


Is there a built-in function in C that can be used for sorting data?

0 Answers  


Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.

0 Answers  


what is a far pointer

12 Answers   ABB, DRDO, ITI, Maruti Suzuki, Steel Plant, TCS, Toyota, Vivo Mobiles,


Explain what is a pragma?

0 Answers  






define c

6 Answers   HCL, TCS,


How can I call fortran?

0 Answers  


write a program to find the given number is prime or not

2 Answers   Accenture, Vasutech,


how to write a data 10 in address location 0x2000

3 Answers  


What should not contain a header file?

2 Answers  


Who is the founder of c language?

0 Answers  


a program that performs some preliminary processing in C, it acts upon certain directives that will affect how the compiler does its work a) compiler b) loader c) directive d) preprocessor

0 Answers  


Categories