Reading and Printing array elements

Reading and Printing array elements:

To read array elements we have to use a looping statement like,

main()
{
int n, i, a[50];

printf("\nEnter the number of elements : ");
scanf("%d",&n);

printf("\nEnter the elements - ");
for(i=0; i < n; i++)
{
  scanf("%d",&a[i]);
}

printf("\nElements of array are - \n ");
for(i=0; i < n; i++)
{
  printf("\n %d",a[i]);
}

}

In the above initially variables n,i and array by name a with maximum of 50 element are declared. Value for n will be inputted. Then the first for loop accepts values for a[0], a[1], a[2], ... a[n-1]. Second for loop prints the values of a[0], a[1], a[2], ... a[n-1]. 

Comments