An array is a collection of elements of the same data type stored in contiguous memory locations. Each element in an array is identified by its index number, which starts from 0. In this program, an integer array named r stores five values. A for loop is then used to display all the elements of the array one by one.
How It Works?
r[5] and an integer variable k.0 to 4.for loop with k = 0.k <= 4.r[k].k by 1 after each iteration.#include <stdio.h> #include <conio.h> main() { int r[5]; int k; clrscr(); r[0] = 10; r[1] = 9; r[2] = 12; r[3] = 42; r[4] = 19; for(k = 0; k <= 4; k++) { printf("\n %d", r[k]); } getch(); }
for loop.for loop.6. Store values in indexes 0 to 5. Use a for loop from 0 to 5 and print each element using r[k].#include <stdio.h> #include <conio.h> main() { int r[6]; int k; clrscr(); r[0] = 15; r[1] = 22; r[2] = 8; r[3] = 41; r[4] = 30; r[5] = 17; for(k = 0; k <= 5; k++) { printf("\n %d", r[k]); } getch(); }
6 and stores six values using array indexes 0 to 5. A for loop accesses each element one by one using r[k] and displays all the values on the screen.