Traversing of an Array

void main()
int a[50],i,n;
printf(“\n Enter the number of total elements = “);
printf(” Enter the value of all elements = “);
printf(” The Traversed Array Elements are :\n”);
printf(” Element number is %d and its value is %d .\n”,i+1,a[i]);

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 *