arrays ppt
arrays ppt
BY,
C.SARAVANAN,
ASSISTANT PROFESSOR/CSE
MANAKULA VINAYAGAR INSTITUTE OF
TECHNOLOGY
ARRAYS
⦿ Arrays are used to store multiple values in a
single variable, instead of declaring separate
variables for each value.
⦿ To create an array, define the data type
(like int) and specify the name of the array
followed by square brackets [].
#include <stdio.h>
int main() {
int myNumbers[] = {25, 50, 75, 100};
myNumbers[0] = 33;
printf("%d", myNumbers[0]);
return 0;
}
LOOP THROUGH AN ARRAY
#include <stdio.h>
int main() {
int myNumbers[] = {25, 50, 75, 100};
int i;
return 0;
}
MULTIDIMENSIONAL ARRAYS
#include <stdio.h>
int main() {
int matrix[2][3] = { {1, 4, 2}, {3, 6, 8} };
printf("%d", matrix[0][2]);
return 0;
}
Output:
2
LOOP THROUGH A 2D ARRAY
#include <stdio.h>
int main() {
int matrix[2][3] = { {1, 4, 2}, {3, 6, 8} };
int i, j;
for (i = 0; i < 2; i++) {
for (j = 0; j < 3; j++) {
printf("%d\n", matrix[i][j]);
}
}
return 0;
}