Traversing of an Array

#include<stdio.h>
#include<conio.h>
void main()
{
int a[50],i,n;
clrscr();
printf(“\n Enter the number of total elements = “);
scanf(“%d”,&n);
printf(” Enter the value of all elements = “);
for(i=0;i<n;i++)
{
scanf(“%d”,&a[i]);
}
printf(” The Traversed Array Elements are :\n”);
for(i=0;i<n;i++)
{
printf(” Element number is %d and its value is %d .\n”,i+1,a[i]);
}
getch();
}

Explanation of Program :
1. We take an array with name A
.
2 We take second variable with namen which store the total number of elements .
3 we take another variable i for looping control .                                              4  Print message for user to enter the total number of elements .            5  Take user’s input and convert it into int and assign to n .
6 Print message for user to enter the value of all elements .
7 Take user’s input and store it in array A .

8 now Traverse the array elements ,in this example we traverse our array by add 2 in each element .                                                                              9 Print result to user on Output Screen .

Output : 

Posted in: C

Leave a Reply

Your email address will not be published. Required fields are marked *