Matrix Addition using C Program
Code:
#include<stdio.h>
void main(){
int first[100][100],second[100][100],sum[100][100],r,c,i,j;
printf("enter row and colume :");
scanf("%d%d", &r,&c);
printf("enter first matrix element : \n");
for(i=0;i<r;i++){
for(j=0;j<c;j++){
scanf("%d", &first[i][j]);
}
}
for(i=0;i<r;i++){
for(j=0;j<c;j++){
printf(" %d ", first[i][j]);
}
printf("\n");
}
printf("enter second matrix element : \n");
for(i=0;i<r;i++){
for(j=0;j<c;j++){
scanf("%d", &second[i][j]);
}
}
for(i=0;i<r;i++){
for(j=0;j<c;j++){
printf(" %d ", second[i][j]);
}
printf("\n");
}
printf("substraction of the two matrix : \n");
for(i=0;i<r;i++){
for(j=0;j<c;j++){
sum[i][j]=first[i][j] - second[i][j];
printf(" %d ",sum[i][j]);
}
printf("\n");
}
}
int first[100][100],second[100][100],sum[100][100],r,c,i,j;
printf("enter row and colume :");
scanf("%d%d", &r,&c);
printf("enter first matrix element : \n");
for(i=0;i<r;i++){
for(j=0;j<c;j++){
scanf("%d", &first[i][j]);
}
}
for(i=0;i<r;i++){
for(j=0;j<c;j++){
printf(" %d ", first[i][j]);
}
printf("\n");
}
printf("enter second matrix element : \n");
for(i=0;i<r;i++){
for(j=0;j<c;j++){
scanf("%d", &second[i][j]);
}
}
for(i=0;i<r;i++){
for(j=0;j<c;j++){
printf(" %d ", second[i][j]);
}
printf("\n");
}
printf("substraction of the two matrix : \n");
for(i=0;i<r;i++){
for(j=0;j<c;j++){
sum[i][j]=first[i][j] - second[i][j];
printf(" %d ",sum[i][j]);
}
printf("\n");
}
}
Comments
Post a Comment