Pages

Thursday, March 10, 2016

C program to print array elements in reverse order.

Printing Array Elements in Reverse Order

#include<stdio.h>
int main()
{
 int i, arr1[5];
 for(i=0; i<5; i++)
 {
  printf("Enter Element[%d]:", i);
  scanf("%d",&arr1[i]);
 }
 printf("\n");
 printf("Array elements in reverse order are:\n");
 for(i=4; i>=0; i--)
 {
  printf("Element[%d]: %d \n", i,arr1[i]);
 }
 return 0;
}

Output of program

Enter Element[0]:1
Enter Element[1]:2
Enter Element[2]:3
Enter Element[3]:4
Enter Element[4]:5

Array elements in reverse order are:
Element[4]: 5
Element[3]: 4
Element[2]: 3
Element[1]: 2
Element[0]: 1

No comments:

Post a Comment