c program to add two matrices

list of programs below:  c program to add two matrices using functions,
c program to add two matrices without functions

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

Matrix A

a b
c d

Matrix B

1 2
3 4

Resultant Matrix of Addition of two matrices A and B are

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

c program to add two matrices using functions, c program for sum of matrices
c program to add two matrices using functions without functions

Write a C program to add two matrices without functions

Write a C program to find addition of two matrices without functions

#include<stdio.h>
void main()
{
int a[5][5],b[5][5],c[5][5],i,j,k,sum=0,m,n,o,p;
//your can specify maximum 5 x 5 matrix with above initialization
printf(“\n To find addition of two matrices”);
printf(“\n Enter the no of rows and columns of first matrix”);
scanf(“%d %d”,&m,&n);
printf(“\n Enter the no of rows and columns of matrix”);
scanf(“%d %d”,&o,&p);
if(m!=o || n!=p)
{
printf(“Matrix addition is not possible”);
printf(“\n rows and columns of first matrix must be same as rows and columns of second matrix”);
}
else
{
printf(“\n Enter the First matrix->”);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf(“%d”,&a[i][j]);
printf(“\n Enter 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(“\n The 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(“\n The 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]);
}
}
}

Write a C program to find sum of two matrices using functions

Write a C program to add  two matrices using functions / write a c program to find sum of two matrices using functions

#include<stdio.h>
void main()
{
int a[5][5],b[5][5],c[5][5],i,j,k,sum=0,m,n,o,p;
//your can specify maximum 5 x 5 matrix with above initialization
printf(“\n To find addition of two matrices”);
printf(“\n Enter the no of rows and columns of first matrix”);
scanf(“%d %d”,&m,&n);
printf(“\n Enter the no of rows and columns of matrix”);
scanf(“%d %d”,&o,&p);
if(m!=o || n!=p)
{
printf(“Matrix addition is not possible”);
printf(“\n rows and columns of first matrix must be same as rows and columns of second matrix”);
}
else
{
printf(“\n Enter the First matrix->”);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf(“%d”,&a[i][j]);
printf(“\n Enter the Second matrix->”);
for(i=0;i<o;i++)
for(j=0;j<p;j++)
scanf(“%d”,&b[i][j]);
printf(“\n The First matrix is\n”);
display_matrix(a[5][5], m, n );
printf(“\n The second matrix is\n”);
display_matrix(b[5][5], m, n );
printf(“\n The sum of two matrices is\n”);
Addition_matrix(a[5][5],b[5][5], m, n );
}
getch();
}

// function to display matrices

void display_matrix(int a[5][5], int m, int n )
{
int i,j;
for(i=0;i<m;i++)
{
printf(“\n”);
for(j=0;j<n;j++)
{
printf(“%d\t”,a[i][j]);
}
}
}

// function to add matrices
void Addition_matrix(int a[5][5], int b[5][5],int  m, int n )

{
int i,j;
for(i=0;i<m;i++)
{
printf(“\n”);
for(j=0;j<n;j++)
{
printf(“%d\t”,a[i][j] + b[i][j]);
}
}
}

Other programs:

Static variable scope
Register variable scope
External variable scope
Automatic variable scope
amicable number
Prime number
Perfect number
Palindrome number
Strong number
Find Factorial 
Biggest Number
Average of n numbers
decimal number to octal
convert decimal number to hexadecimal
decimal number to binary
simple interest
compound interest
Add sparce matrices
Add matrices
 file copying
Palindrome string
Reverse string
String length
Replace characters in string
substring or not using arrays
First occurrence of character in string
Last occurrence of character in string
Convert to uppercase
Convert to lowercase
Concatenate strings 
Compare strings
Generate Employee payslips
Count students scoring marks>50%
convert weight into grams

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *