Translate

Labels

Wednesday 3 April 2013

PROCESSING ONE DIMENSIONAL ARRAYS

TO ILLUSTRATE DECLARATION, INITIALIZATION OF A ONE-DIMENSIONAL ARRAY AND DISPLAYS ITS ELEMENTS.

#include<stdio.h>
#include<conio.h>
void main()
{
int i,a[5]={2,3,5,6,7};
clrscr();
printf("The elements of array a \n");
for(i=0;i<=4;i++)
printf("%3d",a[i]);
getch();
}
OUTPUT:
The element of array a
2   3   5   6   7
Explanation
a is declared to be an array of int type and of size five and also is initialized while it is declared.i is a variable of int type and it is used to traverse the elements of a.
To display the elements of a,we have used for loop to repeatedly call printf().The loop variable i is made to range from 0 to 4.When i takes 0, the first element is displayed.When i takes 1,the second element is displayed and so on.  

No comments: