Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- void main()
- {
- int i,j,r1,r2,c1,c2,k,a[100][100],b[100][100],c[100][100];
- goto input;
- input:
- {
- printf("Enter the number of rows and columns of matrix A: ");
- scanf("%d%d",&r1,&c1);
- printf("\nEnter the number of rows and columns of matrix B: ");
- scanf("%d%d",&r2,&c2);
- }
- if(c1!=r2)
- {
- printf("\nThe matrices cannot be multiplied. Try again\n\n");
- goto input;
- }
- printf("\nEnter the elements of matrix A: ");
- for(i=0;i<r1;i++)
- {
- for(j=0;j<c1;j++)
- scanf("%d",&a[i][j]);
- }
- printf("\nEnter the elements of matrix B: ");
- for(i=0;i<r2;i++)
- {
- for(j=0;j<c2;j++)
- scanf("%d",&b[i][j]);
- }
- for(i=0;i<r1;i++)
- {
- for(j=0;j<c2;j++)
- {
- c[i][j]=0;
- for(k=0;k<c1;k++)
- c[i][j]+=a[i][k]*b[k][j];
- }
- }
- printf("\nThe entered matrix A is\n");
- for(i=0;i<r1;i++)
- {
- for(j=0;j<c1;j++)
- {
- printf("%d\t",a[i][j]);
- }
- printf("\n");
- }
- printf("\nThe entered matrix B is\n");
- for(i=0;i<r2;i++)
- {
- for(j=0;j<c2;j++)
- {
- printf("%d\t",b[i][j]);
- }
- printf("\n");
- }
- printf("\nThe product of the matrices A & B i.e C is\n");
- for(i=0;i<r1;i++)
- {
- for(j=0;j<c2;j++)
- {
- printf("%d\t",c[i][j]);
- }
- printf("\n");
- }
- }
Add Comment
Please, Sign In to add comment