C Program input/output of an array with the help of a for loop

In this example, we declare one array and perform input-output operation on it.

Array Input Output Program

	
#include <stdio.h>

int main() {
    int values[5];

    printf("Enter 5 integers: ");

    // Storing inputted value to array
    for(int i = 0; i < 5; ++i) {
        scanf("%d", &values[i]);
    }

    printf("Displaying integers: ");

    // printing elements of an array
    for(int i = 0; i < 5; ++i) {
        printf("%d\n", values[i]);
    }
    return 0;
}        
	

Output :

	
Enter 5 integers: 10
20
30
40
50
Displaying integers: 10
20
30
40
50
	

In this example, we take integer values as input but we can use any data type with array like float, char.


Share your thoughts

Ask anything about this examples