OpenStudy (anonymous):

How to make a c program that computes for matrix operations (addition,subtraction,multiplication) (max of 3x3, can be 2x1, 1x3, etc.) using arrays and for loops? Please help me! :( i'm using dev-c++ compiler

6 years ago
OpenStudy (anonymous):

its very easy for addition and subtraction: for example for addition: #include<stdio.h> #include<conio.h> void main() { int a[5][5],b[5][5],c[5][5],d[i][j],m,n,p,q,i,j,k; clrscr(); printf("\nEnter the number of rows and columns in matrix A"); scanf("%d%d",&m,&n); printf("\nEnter the elements into the matrix a"); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&a[i][j]); } } printf("\nEnter the number of rows and columns in matrix B"); scanf("%d%d",&p,&q); printf("\nEnter the elements into the matrix a"); for(i=0;i<p;i++) { for(j=0;j<q;j++) { scanf("%d",&b[i][j]); } } //Addition for(i=0;i<m;i++) { for(j=0;j<n;j++) { c[i][j]=a[i][j]+b[i][j]; } } //subtraction for(i=0;i<m;i++) { for(j=0;j<n;j++) { d[i][j]=a[i][j]-b[i][j]; } } for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf("%d",c[i][j]); } }for(i=0;i<m;i++) { for(j=0;j<n;j++) { printf("%d",d[i][j]); } } getch(); }

6 years ago