Traversing Linear Arrays Program In C
Traversing Linear Arrays Program In C |
An array can be defined as a
finite ordered set of homogeneous elements. By the term ‘finite’ we mean that there is a
specific number of elements in an array. By the term ordered we mean that
elements of array are arranged in a sequence so that first, second, third…..,
nth element can be identified. The homogeneous property of array means that all
elements in the array must be of the same type. It is used to handle large
amount of data, without the need to declare many individual variables
separately. The array elements are stored in contiguous memory locations (i.e.
one after the other). All the array elements must be either of any data types
like int, float, char, double etc. or they can be of any user-defined data
types like structures and unions.
Program:
#include <stdio.h>
#include <stdlib.h>
void main()
{
int list[5],i;
/* Getting Array Elements From User*/
printf("Enter array elements: \n");
for(i=0;i<5;i++){
scanf("%d",&list[i]);
printf("\n");
}
/* Traversing Array and Displaying them */
for(i=0;i<5;i++){
printf("\n List[%d] = %d",i,list[i]);
}
getch();
}
Post a Comment