-
Notifications
You must be signed in to change notification settings - Fork 0
/
2D 5x5 Array.c
64 lines (47 loc) · 1.64 KB
/
2D 5x5 Array.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
54
55
56
57
58
59
60
61
62
63
64
#include <stdio.h>
int main() {
int matrix[5][5] = {0};
char check, x_char, y_char, value_char;
printf("Enter 'n' to quit.\n");
while (1) {
printf("Do you want to continue? y for yes, n for no: ");
check = getchar();
if (check == 'n' || check == 'N') {
break;
} else if(check == 'y' || check =='Y') {
while (getchar() != '\n');
printf("\nEnter the x coordinate: ");
x_char = getchar();
int x = x_char - '0';
printf("%d", x);
while (getchar() != '\n');
printf("Enter the y coordinate: ");
y_char = getchar();
int y = y_char - '0';
printf("%d", y);
while (getchar() != '\n');
printf("Enter the value: ");
value_char = getchar();
int value = value_char - '0';
printf("%d", value);
while (getchar() != '\n');
if (x > 0 && x < 6 && y > 1 && y < 6) {
matrix[x-1][y-1] = value;
} else {
printf("Invalid coordinates. Please enter values between 1 and 5.\n");
}
printf("\nUpdated Matrix:\n");
for (int row = 0; row < 5; row++) {
for (int col = 0; col < 5; col++) {
printf("%d ", matrix[col][row]);
}
printf("\n");
}
}else if (check == '\n' || check == ' ' || check == '\t') {
continue;
} else {
printf("\nThat was an invalid input, please try again\n");
}
}
return 0;
}