Using for Loops for Sequential Access:

Arrays are commonly processed using loops, particularly the for loop. Since the
elements of an array are stored in contiguous memory locations and accessed using
indices, a loop provides an efficient way to access each element sequentially.

Sequential access allows operations such as reading input values, displaying
output, computing sums or averages, and searching for specific values. The loop
control variable typically corresponds to the array subscript.
SYNTAX:

for(int i = 0; i < 5; i++)
{
    scanf("%d", &marks[i]);
}
EXAMPLE:

#include <stdio.h>

int main() {
    int tinWeight[5]={1,2,3,4,5};

    

    
    for(int i = 0; i < 5; i++) {
        printf("Index [%d] = %d\n", i, tinWeight[i]);
    }

    return 0;
}
Previous Next