This is a program for the addition, multiplication and transpose of matrices. If you have any doubts, please let me know.
#include<stdio.h> main() { int m,n,i,j,k,p,q,r,a[25][25],b[25][25],c[25][25],ch; printf("\n Enter the rows and columns"); scanf("%d %d",&m,&n); printf("\n Enter the value of the array"); for(i=0;i<m;i++) { for(j=0;j<n;j++) scanf("%d",&a[i][j]); } printf("\n MENU \n 1)addition 2)multiplication 3)transpose \n Enter your choice"); scanf("%d",&ch); if(ch==1) { printf("\n Enter the value of the array b"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&b[i][j]); c[i][j]=a[i][j]+b[i][j]; } } printf("\n the array is \n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf(" %d ",c[i][j]); } printf("\n"); } } if(ch==2) { printf("\n Enter the value of array b"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&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][i]; } } } printf("\n the new array is \n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf(" %d ",c[i][j]); } printf("\n"); } } if(ch==3) { for(i=0;i<m;i++) { for(j=0;j<n;j++) b[i][j]=a[j][i]; } printf("\n the new array is \n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf(" %d ",b[i][j]); } printf("\n"); } } }
#include<stdio.h> main() { int m,n,i,j,k,p,q,r,a[25][25],b[25][25],c[25][25],ch; printf("\n Enter the rows and columns"); scanf("%d %d",&m,&n); printf("\n Enter the value of the array"); for(i=0;i<m;i++) { for(j=0;j<n;j++) scanf("%d",&a[i][j]); } printf("\n MENU \n 1)addition 2)multiplication 3)transpose \n Enter your choice"); scanf("%d",&ch); if(ch==1) { printf("\n Enter the value of the array b"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&b[i][j]); c[i][j]=a[i][j]+b[i][j]; } } printf("\n the array is \n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf(" %d ",c[i][j]); } printf("\n"); } } if(ch==2) { printf("\n Enter the value of array b"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&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][i]; } } } printf("\n the new array is \n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf(" %d ",c[i][j]); } printf("\n"); } } if(ch==3) { for(i=0;i<m;i++) { for(j=0;j<n;j++) b[i][j]=a[j][i]; } printf("\n the new array is \n"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf(" %d ",b[i][j]); } printf("\n"); } } }
No comments:
Post a Comment