-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpointers9.c
53 lines (40 loc) · 1.25 KB
/
pointers9.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
47
48
49
50
51
52
53
#include <stdio.h>
//Add 2 matrices - pointers
#define max_size 100
int getMat(int (*)[], int, int);
int printMat(int (*)[], int, int);
int main () {
int mat1[max_size][max_size], mat2[max_size][max_size];
int rows, cols;
printf("Enter the no of rows ");
scanf("%d", &rows);
printf("Enter the no of cols ");
scanf("%d", &cols);
getMat(mat1, rows, cols);
printMat(mat1, rows, cols);
}
int getMat(int (*mat)[max_size], int rows, int cols) {
for (int i=0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
printf("Enter the element at row[%d] col[%d] ", i + 1, j + 1);
scanf("%d", (*(mat + i) + j));
}
}
return 0;
}
int printMat(int (*mat)[max_size], int rows, int cols) {
for (int i=0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
printf("The element at row[%d] col[%d] is %d ", i + 1, j + 1, *(*(mat + i) + j));
printf("\n");
}
printf("\n");
}
printf("Matrix is ");
for (int i=0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
printf("%d ", *(*(mat + i) + j));
}
printf("\n");
}
}