Sunday 28 February 2016

Array in reverse order

Q. Write a C program to display the array in reverse order.

Ans.

/*c program for display the array in reverse order*/
#include<stdio.h>
#include<conio.h>
#define SIZE 50
int main()
{
 int arr[SIZE];
 int i,index,tmp,num;
 printf("Enter total number of element in array : ");
 scanf("%d", &num);
 for(i=0; i<num; i++)
 {
  printf("Enter %d element : ",i+1);
  scanf("%d", &arr[i]);
 }
 printf("\n-- Array in reverse order --\n\n");
 for(i=0; i<num; i++);
 for(i--; i>=0; i--)
    printf("\t%d\n",arr[i]);
 getch();
 return 0;

}

No comments:

Post a Comment

Ads Inside Post