In this program, you'll learn to display array elements. An array is a collection of homogeneous (same type) data items stored in contiguous memory locations. For example if an array is of type “int”, it can only store integer elements and cannot allow the elements of other types such as double, float, char etc. An element is accessed by indexing the array name. This is done by placing the index of the element within square brackets after the name of the array. For example − int max = arr[2];
#include<stdio.h>
int main()
{
int a[5];
int i=0;
printf("Enter 5 numbers: ");
for(i=0; i<5; i++)
{
scanf("%d", &a[i]);
}
printf("\nArray elements are..\n");
for(i=0; i<5; i++)
{
printf("a[%d] = %d\n", i, a[i]);
}
return 0;
}
Enter 5 numbers:
47
51
68
91
105
Array elements are..
a[0] = 47
a[1] = 51
a[2] = 68
a[3] = 91
a[4] = 105