C Program to find sum of two matrices write code

itstudentjunction



C Program to find sum of two matrices write code


How is matrix addition performed?

Rule: two matrices can only be addedd if both are in same order.


eg.

  MAtrix A

a b
c d
MAtrix B

1 2
3 4
Resultant Matrix c

a + 1 , b +2
c + 3 , d + 4





Write a C program to add two matrices



Write a C program to find addition of two matrices / wtite a c program to find sum of two matrices

#include<stdio.h>
void main(){
int a[5][5],b[5][5],c[5][5],i,j,k,sum=0,m,n,o,p;
printf("\nTo find addition of two matrices");
printf("\nEnter the row and column of first matrix");
scanf("%d %d",&m,&n);
printf("\nEnter the row and column of second matrix");
scanf("%d %d",&o,&p);
if(m!=o || n!=p){
printf("Matrix addition is not possible");
printf("\nColumn of first matrix must be same as row of second matrix");
}
else{
printf("\nEnter the First matrix->");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("\nEnter the Second matrix->");
for(i=0;i<o;i++)
for(j=0;j<p;j++)
scanf("%d",&b[i][j]);
printf("\nThe First matrix is\n");
for(i=0;i<m;i++){
printf("\n");
for(j=0;j<n;j++){
printf("%d\t",a[i][j]);
}
}
printf("\nThe Second matrix is\n");
for(i=0;i<o;i++){
printf("\n");
for(j=0;j<p;j++){
printf("%d\t",b[i][j]);
}
}
printf("\nThe sum of two matrices is\n");

for(i=0;i<m;i++){ //row of first matrix
for(j=0;j<p;j++){ //column of second matrix
{
c[i][j]=a[i][j]+b[i][j];
}


for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<p;j++)
{
printf("%d\t",c[i][j]);
}
}
}



Other matrices programs:



write a c program for addition of two matrices
write a c pprogram to show multiplication of two matrices

write a c program to find transpose of a matrix

write a c program to find inverse of matrix

write a c program to find lower triangle of a matrix
write a c program to find upper triangle of a matrix
write a c program to implement sparse matrix
write a c program to multiply two sparse matrices



list of c programs




Most popular programs


write a program to find factorial using c
WAP to Calculate Simple Interest
Check for even / odd
perfect or not
write a C program to find sum of two matrices
display numbers pyramid
show amicable pairs
factors of a number using for loop, while
print prime factors using C
convert to uppercase
write a program for prime numbers using for loop
write a program to implement pascal Triangle
check reverse string arrays
find string length strlen
Calculate compound Interest
check armstrong number or not
print prime numbers using while
solve towers of hanoi
Display Floyd’s Triangle
reverse string using pointers
write a program to find a number is prime or not
Show revers number
calculate LCM concatinate strings using arrays
write a program to find palindrome or not
WAP to print sum of Digits
display transpose matrix
show lower triangle
multipiy two matrices
write a program to calculate GCD
strong number or not
check substring in c
string length using arrays
string length using pointers
convert to lowercase
WAP to find factors
count no.of digits
show inverse of matrix
show reverse string strrev
write a program to display upper triangle
concatinate strings strCat
convert to lowercase
check for palindrome string
print substring position
compare two strings arrays
compare strings strcmp
find roots of quadriaic expression
show fibonacci numbers
factorial using recurrsion
sum of factorial series
convert decimal to binary
Write a program to print armstrong numbers

decimal to octal
compare strings pointers
decimal to hexadecimal
sum of n numbers
average of n
largest of two
largest of n

strong numbers
perfect numbers using for loop

 



C Programs Data structures Programs in c Data structures Progra+ms in c++ Unix commands Linux commands C++ programs Data structures Algorithms Java Programs UML Diagrams Assembly Language Programs DBMS j2ee programming