C program to add two matrices into single Matrix

Simple C program to do addition of given matrices

Code:

#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

int a[4][4],b[4][4],c[4][4];

int i,j,k,m,n,p,q;

printf("\nenter no. of rows for matrix A:");

scanf("%d",&m);

printf("\nenter no. of coloums for matrix A:");

scanf("%d",&n);

printf("\nenter no. of rows for matrix B:");

scanf("%d",&p);

printf("\nenter no. of coloums for matrix B:");

scanf("%d",&q);

printf("\nenter array A:\n");

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

{

scanf("%d",&a[i][j]);

}

printf("\n");

}

printf("\nenter array B:\n");

for(i=0;i<p;i++)

{

for(j=0;j<q;j++)

{

scanf("%d",&b[i][j]);

}

printf("\n");

}



if((m==p)&&(n==q))

{

printf("\naddition of array is:\n");

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

{

c[i][j]=a[i][j]+b[i][j];

printf("%d ",c[i][j]);

}

printf("\n");

}}

else

{printf("\nno. cant be added");

}

getch();

}

Comments

Popular posts from this blog

C program to evaluate Prefix Expression using Stack data structure

Servlet Program to Print Today’s Date and Time using refresh header

Java Program to Implement sorting algorithm using TCP on Server application