C Program to Read an Array and Displaying its Content

Question: Write a program in C to read an array containing 5 numbers and display its content.

Reading and Displaying Array


#include<stdio.h>

int main()
{
 int i, arr[5];
 
 /* Reading Array */
 printf(“Enter 5 numbers:\n”);
 for (i=0; i< 5; i++)
 {
     printf(“arr[%d] = ” , i );
     scanf(“%d”, &arr[i]);
 }
 /* Displaying array content */
 printf(“Array content is:\n”);
 for (i=0; i< 5; i++)
 {
     printf(“arr[%d] = %d\n”, i, arr[i] );
 }
 return 0;
}

Output

Enter 5 numbers:
arr[0] = 11↲
arr[1] = 25↲
arr[2] = 85↲
arr[3] = -19↲
arr[4] = 121↲
Array content is:
arr[0] = 11
arr[1] = 25
arr[2] = 85
arr[3] = -19
arr[4] = 121