by Dinesh Thakur Category: Array

An array is similar to a list in which the objects are of the same type and stored in sequential memory blocks; this is the only relationship between the elements of an array. The input/output of values of elements of an array cannot be done as whole of array, but is carried out element by element. This may be done by accessing each element by its index value. Therefore, for large arrays, either a for loop or a while loop may be used for accessing each element for its input/output. For example, if elements of an array Array [4] having 4 elements are to be processed for input /output by user of a program, the program code may be written as follows:

int i,j;

int Kim[4];

printf("Write 4 elements of Ele");


scanf("%d", & Ele[i]); //for input of array elements.

for(j =0; j<4; j++) // for output of array elements.

printf( "%d\t" , Ele[j];

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

void main()
  int A [4] , Sum = 0;
  int i,j , k;
  printf("Write the four elements of array A:");
  for(i =0; i<4; i++) // input of array elements
    for ( j=0; j<4; j++) //output of array elements
    printf("A(%d) = %d, ", j, A[j] );
      Sum+= A[k]; //manipulation with array elements
      printf ( "\n Sum = %d\n",Sum);


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

About Dinesh Thakur


Related Articles