#include <stdio.h>
#include<stdio.h>
int main()
{
int row, colum, row_element, colum_element, first[50][50], second[50][50], sum[50][50];
printf("Enter the number of rows and columns of matrix\n");
scanf("%d%d", &row, &colum);
if(row>0&&colum>0)
{
printf("Enter the elements of first matrix\n");
for (row_element = 0; row_element < row; row_element++)
{
for (colum_element= 0; colum_element <colum; colum_element++)
{
scanf("%d", &first[row_element][colum_element]);
}
}
printf("Enter the elements of second matrix\n");
for (row_element = 0; row_element < row; row_element++)
{
for (colum_element = 0 ; colum_element< colum; colum_element++)
{
scanf("%d", &second[row_element][colum_element]);
}
}
printf("Sum of entered matrices:-\n");
for (row_element = 0; row_element< row; row_element++)
{
for (colum_element= 0 ; colum_element < colum; colum_element++)
{
sum[row_element][colum_element] = first[row_element][colum_element] + second[row_element][colum_element];
printf("%d\t", sum[row_element][colum_element]);
}
printf("\n");
}
}
else
printf("please enter positive number only");
}
output
Enter the number of rows and columns of matrix
2 2
Enter the elements of first matrix 1
2
3
2
Enter the elements of second matrix 2
3
2
1
Sum of entered matrices:-
3 5
5 3
#include<stdio.h>
int main()
{
int row, colum, row_element, colum_element, first[50][50], second[50][50], sum[50][50];
printf("Enter the number of rows and columns of matrix\n");
scanf("%d%d", &row, &colum);
if(row>0&&colum>0)
{
printf("Enter the elements of first matrix\n");
for (row_element = 0; row_element < row; row_element++)
{
for (colum_element= 0; colum_element <colum; colum_element++)
{
scanf("%d", &first[row_element][colum_element]);
}
}
printf("Enter the elements of second matrix\n");
for (row_element = 0; row_element < row; row_element++)
{
for (colum_element = 0 ; colum_element< colum; colum_element++)
{
scanf("%d", &second[row_element][colum_element]);
}
}
printf("Sum of entered matrices:-\n");
for (row_element = 0; row_element< row; row_element++)
{
for (colum_element= 0 ; colum_element < colum; colum_element++)
{
sum[row_element][colum_element] = first[row_element][colum_element] + second[row_element][colum_element];
printf("%d\t", sum[row_element][colum_element]);
}
printf("\n");
}
}
else
printf("please enter positive number only");
}
output
Enter the number of rows and columns of matrix
2 2
Enter the elements of first matrix 1
2
3
2
Enter the elements of second matrix 2
3
2
1
Sum of entered matrices:-
3 5
5 3
No comments:
Post a Comment