/* ADDITION OF TWO MATRICES*/
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main( )
{
int a[10][10],b[10][10],c[10][10];
int i,j,m,n,p,q;
printf("\n Enter the size of matrix A:");
scanf("%d%d",&m,&n);
printf("\n Enter the size of Matrix B:");
scanf("%d%d",&p,&q);
if(m!=p||n!=q)
{
printf("Matrix addition not possible.");
exit(0);
}
printf(" Enter the matrix B values:\n");
for(i=0;i<m;i )
for(j=0;j<n;j )
scanf("%d",&a[i][j]);
print("Enter the Matrix B values:\n");
for(i=0;i<p;i )
for(j=0;j<n;j )
c[i][j]=a[i][j] b[i][j];
printf("\n The Matrix A is \n");
for(i=0;i<m;i )
{
for(j=0;j<n;j )
printf('%d",a[i][j]);
print("\n");
}
printf("\n The Martix B is\n");
for(i=0;i<p;i )
{
for(j=0;j<q;b[i][j]);
printf("%d",b[i][j]);
printf("\n");
}
printf("\n The Output Matrix C is\n");
for(i=0;i<m;i )
{
for(j=0;j<n;j )
printf("%d",c[i][j]);
printf("\n");
}
}
OUTPUT :
Enter the size of Matrix A:2
3
Enter the size of Matrix B:2
3
Enter the matrix A values:
1
2
3
4
5
6
Enter the Matrix B values:
6
5
4
3
2
1
The Matrix A is
1 2 3
4 5 6
The matrix B is
6 5 4
3 2 1
The Output Matrix C is
7 7 7
7 7 7
Recommended Questions
Useful Files
Users Joined
/* ADDITION OF TWO MATRICES*/
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main( )
{
int a[10][10],b[10][10],c[10][10];
int i,j,m,n,p,q;
printf("\n Enter the size of matrix A:");
scanf("%d%d",&m,&n);
printf("\n Enter the size of Matrix B:");
scanf("%d%d",&p,&q);
if(m!=p||n!=q)
{
printf("Matrix addition not possible.");
exit(0);
}
printf(" Enter the matrix B values:\n");
for(i=0;i<m;i )
for(j=0;j<n;j )
scanf("%d",&a[i][j]);
print("Enter the Matrix B values:\n");
for(i=0;i<p;i )
for(j=0;j<n;j )
c[i][j]=a[i][j] b[i][j];
printf("\n The Matrix A is \n");
for(i=0;i<m;i )
{
for(j=0;j<n;j )
printf('%d",a[i][j]);
print("\n");
}
printf("\n The Martix B is\n");
for(i=0;i<p;i )
{
for(j=0;j<q;b[i][j]);
printf("%d",b[i][j]);
printf("\n");
}
printf("\n The Output Matrix C is\n");
for(i=0;i<m;i )
{
for(j=0;j<n;j )
printf("%d",c[i][j]);
printf("\n");
}
}
OUTPUT :
Enter the size of Matrix A:2
3
Enter the size of Matrix B:2
3
Enter the matrix A values:
1
2
3
4
5
6
Enter the Matrix B values:
6
5
4
3
2
1
The Matrix A is
1 2 3
4 5 6
The matrix B is
6 5 4
3 2 1
The Output Matrix C is
7 7 7
7 7 7