-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathP-70.c
46 lines (46 loc) · 897 Bytes
/
P-70.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//Write a program in c to add two 2-D array and display it.
#include <stdio.h>
int main()
{
int r,c;
int a[100][100];
int b[100][100];
int sum[100][100];
printf("Enter the number of rows: ");
scanf("%d", &r);
printf("Enter the number of columns: ");
scanf("%d", &c);
printf("Enter elements of 1st matrix:\n");
for (int i = 0; i < r;i++)
{
for (int j = 0; j < c;j++)
{
printf("Enter element a%d%d: ", i,j);
scanf("%d", &a[i][j]);
}
printf("Enter elements of 2nd matrix:\n");
for (int i = 0; i < r;i++)
{
for (int j = 0; j < c;j++)
{
printf("Enter element b%d%d: ", i, j);
scanf("%d", &b[i][j]);
}
for (int i = 0; i < r; ++i)
{
for (int j = 0; j < c; ++j)
{
sum[i][j] = a[i][j] + b[i][j];
}
printf("Sum of two array: \n");
for (int i = 0; i < r; ++i)
{
for (int j = 0; j < c; ++j)
{
printf("%d ", sum[i][j]);
if (j == c - 1)
{
printf("\n");
}
}
}