#include<stdio.h>
int main()
{
int i,j,k,r,c;
printf("Enter the number of rows of arrys:");
scanf("%d",&r);
printf("Enter the number of colums of arrys:");
scanf("%d",&c);
int a[r][c];
int b[r][c];
printf("\nEnter values of first 2d arrays:\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("Enter values of array element for %d row and %d coulm:",i,j);
scanf("%d",&a[i][j]);
}
}
printf("\nEnter values for 2nd arry element\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("Enter values of array element for %d row and %d coulm:",i,j);
scanf("%d",&b[i][j]);
}
}
printf("\n");
printf("First aaray elements are\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%3d",a[i][j]);
}
printf("\n");
}
printf("Second aaray elements are\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%3d",b[i][j]);
}
printf("\n");
}
printf("\n\n\n");
printf("sum of arry element\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%3d",a[i][j]+b[i][j]);
}
printf("\n");
}
getch();
return 0;
}
Expected output of :
Enter the number of rows of arrys:2
Enter the number of colums of arrys:3
Enter values of first 2d arrays:
Enter values of array element for 0 row and 0 coulm:1
Enter values of array element for 0 row and 1 coulm:2
Enter values of array element for 0 row and 2 coulm:3
Enter values of array element for 1 row and 0 coulm:3
Enter values of array element for 1 row and 1 coulm:2
Enter values of array element for 1 row and 2 coulm:1
Enter values for 2nd arry element
Enter values of array element for 0 row and 0 coulm:1
Enter values of array element for 0 row and 1 coulm:2
Enter values of array element for 0 row and 2 coulm:3
Enter values of array element for 1 row and 0 coulm:3
Enter values of array element for 1 row and 1 coulm:2
Enter values of array element for 1 row and 2 coulm:1
First aaray elements are
1 2 3
3 2 1
Second aaray elements are
1 2 3
3 2 1
sum of arry element
2 4 6
6 4 2