Program to find addition or subtraction of matrix using arrays
Program:
#include<stdio.h>
void main()
{
float a[3][3],b[3][3],c[3][3];
int i,j;
printf("Enter numbers for 1st matrix
in rowwise manner:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%f",&a[i][j]);
}
}
printf("Enter numbers for 2nd matrix
in rowwise manner:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%f",&b[i][j]);
c[i][j]=a[i][j]+b[i][j]; // Put
c[i][j]=a[i][j]-b[i][j]; to get subtraction //
}
}
printf("Addition matrix is:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%f\t",c[i][j]);
}
printf("\n");
}
}
Output:
Note:
We know that in an array if we want to add or subtract then we can add or subtract with elements of same row and column number only.
No comments:
Post a Comment