Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* program to read and display matrix multiplication */
- #include<conio.h>
- #include<stdio.h>
- void main()
- {
- int m,n,p,q,a[5][5],b[5][5],c[5][5],i,j,k;
- clrscr();
- printf("Enter no of rows and columns of Array 1:\n");
- scanf("%d%d",&m,&n);
- printf("Enter no of rows and columns of Array 2:\n");
- scanf("%d%d",&p,&q);
- if(m==q && n==p)
- {
- for(i=0;i<m;i++)
- {
- printf("Enter Array 1 elements row %d\n",i+1);
- for(j=0;j<n;j++)
- {
- scanf("%d",&a[i][j]);
- }
- }
- for(i=0;i<p;i++)
- {
- printf("Enter Array 2 elements row %d\n",i+1);
- for(j=0;j<q;j++)
- {
- scanf("%d",&b[i][j]);
- }
- }
- printf("The Array 1 is:\n");
- for(i=0;i<m;i++)
- {
- for(j=0;j<n;j++)
- {
- printf(" %d",a[i][j]);
- }
- printf("\n");
- }
- printf("The Array 2 is:\n");
- for(i=0;i<p;i++)
- {
- for(j=0;j<q;j++)
- {
- printf(" %d",b[i][j]);
- }
- printf("\n");
- }
- 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]+=a[i][k]*b[k][j];
- }
- }
- }
- printf("The Array Multiplied is:\n");
- for(i=0;i<m;i++)
- {
- for(j=0;j<n;j++)
- {
- printf(" %d",c[i][j]);
- }
- printf("\n");
- }
- }
- else
- {
- printf("Array Multiplication NOT possible");
- }
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment