-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpointers 2D Array sum.c
More file actions
67 lines (66 loc) · 1.38 KB
/
pointers 2D Array sum.c
File metadata and controls
67 lines (66 loc) · 1.38 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<stdio.h>
int main()
{
int a,b;
printf("Enter the size of row: \n");
scanf("%d",&a);
printf("Enter the size of column: \n");
scanf("%d",&b);
int arr[a][b];
int *p=&arr[0][0];
printf("Enter the array elements: \n");
for(int i=0;i<a;i++)
{
for(int j=0;j<b;j++)
{
scanf("%d",(p+i*b+j));
}
}
printf("The 1st matrix are: \n");
for(int i=0;i<a;i++)
{
for(int j=0;j<b;j++)
{
printf("%d ",*(p+i*b+j));
}
printf("\n");
}
int arr2[a][b];
int *p2=&arr2[0][0];
printf("Enter the array elements: \n");
for(int i=0;i<a;i++)
{
for(int j=0;j<b;j++)
{
scanf("%d",(p2+i*b+j));
}
}
printf("The 2nd matrix are: \n");
for(int i=0;i<a;i++)
{
for(int j=0;j<b;j++)
{
printf("%d ",*(p2+i*b+j));
}
printf("\n");
}
int sum[a][b];
int *add=&sum[0][0];
for(int i=0;i<a;i++)
{
for(int j=0;j<b;j++)
{
*(add+i*b+j)=(*(p+i*b+j))+(*(p2+i*b+j));
}
}
printf("The sum of array: \n");
for(int i=0;i<a;i++)
{
for(int j=0;j<b;j++)
{
printf("%d ",*(add+i*b+j));
}
printf("\n");
}
return 0;
}