// C program to illustrate matrix addition:
#include <stdio.h>
void main()
{
int row, col, i, j, first[10][10], second[10][10], sum[10][10];
printf("Enter the number of rows and columns of first matrix\n");
scanf("%d%d", &row, &col);
printf("Enter the %d elements of first matrix\n",row * col);
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
scanf("%d", &first[i][j]);
}
}
printf("\nFirst matrix :\n");
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
printf("%d\t", first[i][j]);
}
printf("\n");
}
printf("Enter the number of rows and columns of second matrix\n");
scanf("%d%d", &row, &col);
printf("Enter the %d elements of second matrix\n",row * col);
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
scanf("%d", &second[i][j]);
}
}
printf("\nSecond matrix : \n");
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
printf("%d\t", second[i][j]);
}
printf("\n");
}
printf("Sum of entered matrices:-\n");
for (i = 0; i < row; i++)
{
for (j = 0 ; j < col; j++)
{
sum[i][j] = first[i][j] + second[i][j];
printf("%d\t", sum[i][j]);
}
printf("\n");
}
}
output:
#include <stdio.h>
void main()
{
int row, col, i, j, first[10][10], second[10][10], sum[10][10];
printf("Enter the number of rows and columns of first matrix\n");
scanf("%d%d", &row, &col);
printf("Enter the %d elements of first matrix\n",row * col);
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
scanf("%d", &first[i][j]);
}
}
printf("\nFirst matrix :\n");
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
printf("%d\t", first[i][j]);
}
printf("\n");
}
printf("Enter the number of rows and columns of second matrix\n");
scanf("%d%d", &row, &col);
printf("Enter the %d elements of second matrix\n",row * col);
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
scanf("%d", &second[i][j]);
}
}
printf("\nSecond matrix : \n");
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
printf("%d\t", second[i][j]);
}
printf("\n");
}
printf("Sum of entered matrices:-\n");
for (i = 0; i < row; i++)
{
for (j = 0 ; j < col; j++)
{
sum[i][j] = first[i][j] + second[i][j];
printf("%d\t", sum[i][j]);
}
printf("\n");
}
}
output:
No comments:
Post a Comment