/*Program to Find the Addition and Subtraction of two Matrices*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a[10][10], b[10][10], c[10][10];
int i,j,n,m;
clrscr();
printf("\n\tAddition and Subtraction of two matrices");
printf("\nEnter the no. of rows and columns:");
scanf("%d%d",&m,&n);
printf("\nEnter the first matrix:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\nEnter the first matrix:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("\nAddition of two matrices:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d",a[i][j]+b[i][j]);
printf("\t");
}
printf("\n");
}
printf("\nSubtraction of two matrices:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d",a[i][j]-b[i][j]);
printf("\t");
}
printf("\n");
}
getch();
}
OUTPUT
Addition and Subtraction of two matrices
Enter the no. of rows and columns:2 2
Enter the first matrix:
1 2
3 4
Enter the second matrix:
1 2
3 4
Addition of two matrices:
2 4
6 8
Subtraction of two matrices:
0 0
0 0
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a[10][10], b[10][10], c[10][10];
int i,j,n,m;
clrscr();
printf("\n\tAddition and Subtraction of two matrices");
printf("\nEnter the no. of rows and columns:");
scanf("%d%d",&m,&n);
printf("\nEnter the first matrix:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\nEnter the first matrix:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("\nAddition of two matrices:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d",a[i][j]+b[i][j]);
printf("\t");
}
printf("\n");
}
printf("\nSubtraction of two matrices:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d",a[i][j]-b[i][j]);
printf("\t");
}
printf("\n");
}
getch();
}
OUTPUT
Addition and Subtraction of two matrices
Enter the no. of rows and columns:2 2
Enter the first matrix:
1 2
3 4
Enter the second matrix:
1 2
3 4
Addition of two matrices:
2 4
6 8
Subtraction of two matrices:
0 0
0 0
Comments
Post a Comment