Previous | Home | Next |
Traversing basically means the accessing the each and every element of the array at least once. Traversing is usually done to be aware of the data elements which are present in the array.
After insertion or deletion operation you would usually want to check whether it has been successfully or not, to check this we can use traversing, and can make sure that whether the element is successfully inserted or deleted. Following below is a code snippet which shows how we can do traversing in an linear array.
A program to traverse or read a linear or 1-D array
#include<conio.h>
void main()
{
int a[7], i=0;
clrscr();
printf("Enter the elements of the array :");
for (i=0;i<=6 ;i++ )
{
scanf("%d\n", &a[i]); /* taking input array from the user */
}
printf("\nThe elements of the array you have enetered are as follows :")
for(i=0; i<=6; i++)
{
printf("%d", a[i]); /* printing the array elements or traversing the array */
}
getch();
}
Previous | Home | Next |