-
Notifications
You must be signed in to change notification settings - Fork 0
/
arrays.c
42 lines (33 loc) · 929 Bytes
/
arrays.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
#include <stdio.h>
int main() {
int ages1[10];
// first element - index 0
// 0-9
int size = 10;
int ages2[] = {1, 4, 60, 458, 5484, 52401, 54, 8478, 978, 40};
for (int i = 0; i < size; i++) {
printf("%d ", ages2[i]);
}
ages2[3] = 440;
printf("\n");
for (int i = 0; i < size; i++) {
printf("%d ", ages2[i]);
}
printf("\n");
///////////// Multidimensional Arrays /////////////
int rows = 3;
int columns = 4;
int studentGrades[3][4] = {
{1, 3, 4, 6}, {3, 2, 4, 5}, {32, 2, 4, 9}}; // atleast columns is required
// in declaration
for (int i = 0; i < rows; i++) {
printf("{ ");
for (int k = 0; k < columns; k++) {
printf("%d ", studentGrades[i][k]);
}
printf(" }\n");
}
// Arrays don't have to contain ints, just easiest to start with
// All data does need to be same type, though
return 0;
}