Ads Top

Matrix addition program using c

matrix addition,c ,program,computer,

Matrix addition program

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],i,j,n,m,p,q;
clrscr();
printf("Input rows and columns of matrix A:\n"):
scanf("%d%d",&n,&m);
printf("Input rows and columns of matrix B:\n"):
scanf("%d%d",&p,&q);
if((n==p)&&(m==q))
{
printf("Enter the matrix A:\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)

{
scanf("%d",&a[i][j]);
}
printf(Matrix A is :\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)

{
printf("%d\t",a[i][j])'
}
printf("\n"):
}printf("Enter the matrix B:\n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)

{
scanf("%d",&b[i][j]);
}
printf(Matrix B is :\n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)

{
printf("%d\t",b[i][j])'
}
printf("\n"):
}
printf("The answer is :\n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)

{
c[i][j]=a[i][j]+b[i][j];
printf("%d\t",c[i][j]);
}
printf("\n\n");
}
}
else
{
printf("Matrix addition is not possible");
}
getch();
}


Output

Input rows and columns of matrix A: 2   2
Input rows and columns of matrix B: 2   2
Enter matrix A:1  2   3    4
Matrix A is :
1    2
3    4

Enter matrix B:1   2    3   4 
Matrix B is :
1   2
3   4
The answer is :
2   4  
6   8

No comments:

Touchfeeds. Powered by Blogger.