//Written bu MA Saleh
#include<stdio.h>
int main()
{
int row, col, i, j, k, repeat;
while(1==1)
{
printf("Enter number of rows of your matrix: \n");
scanf("%d", &row);
printf("Enter number of columns of your matrix: \n");
scanf("%d", &col);
if(row <=0 || col <= 0)
{
printf("It is not possible to add\n");
continue;
}
int first_matrix[row][col], second_matrix[row][col], sum[row][col];
for(i = 0; i < row; i++)
{
printf("Enter the element of row %d of first matrix(give a space between two value): \n", i+1);
for(j = 0; j < col; j++)
{
scanf("%d", &first_matrix[i][j]);
}
}
for(i = 0; i < row; i++)
{
printf("Enter the element of row %d of second matrix(give a space between two value): \n", i+1);
for(j = 0; j < col; j++)
{
scanf("%d", &second_matrix[i][j]);
}
}
//add two matrix
for(i = 0; i < row; i++)
{
for(j = 0; j < col; j++)
{
sum[i][j] = first_matrix[i][j] + second_matrix[i][j];
}
}
printf("\n\nYour matrix is: \n");
for(i = 0; i < row; i++)
{
for(j = 0; j < col; j++)
{
printf("%d\t", first_matrix[i][j]);
}
printf("\t");
for(k = 0; k < col; k++)
{
printf("%d\t", second_matrix[i][k]);
}
printf("\n\n");
}
//print the result after add two matrix
printf("The Result is: \n");
for(i = 0; i < row; i++)
{
for(j = 0;j < col; j++)
{
printf("%d\t", sum[i][j]);
}
printf("\n");
}
printf("\nWant to add another matrix?(1. Yes 2. No)\n");
scanf("%d", &repeat);
if(repeat == 1)
{
continue;
}
else
{
break;
}
}
return 0;
// Copyright@MAS
}
Previous Post(Find Max & Min value from an array)
0 comments:
Post a Comment