Arrays: Reading user-entered numbers into an array


#include <stdio.h> int main() { // declare an array and a loop variable. int a[5], i; printf("Enter five numbers:\n"); // read each number from the user for (i = 0; i < 5; i++) { scanf("%d", &a[i]); } printf("The array contains:\n"); // print all the numbers in the array for (i = 0; i < 5; i++) { printf("%d ", a[i]); } return 0; }
10 25 30 26 40
Click on the Run button to get started.
The code/input has changed since you last clicked on Run. Click it
again to see the updated changes.
Comments