Interview Questions   Tutorials   Discussions   Programs   

C - Write a program to display the array elements in reverse order in c language?




261
views
asked marvit August 18, 2014 08:54 AM  

Write a program to display the array elements in reverse order in c language?


           

1 Answers



 
answered By bhjahnavi   0  

/*program to display the array elements in reverse order*/
#include <stdio.h>
 
int main()
{
  int n, c, d, a[100], b[100];
 
  printf("Enter the number of elements in array\n");
  scanf("%d", &n);
 
  printf("Enter the array elements\n");
 
  for (c = 0; c < n ; c++)
   scanf("%d", &a[c]);
 
  
  for (c = n - 1, d = 0; c >= 0; c--, d++)
   b[d] = a[c];
 
  
 
  for (c = 0; c < n; c++)
   a[c] = b[c];
 
  printf("Reverse array is\n");
 
  for (c = 0; c < n; c++)
   printf("%d\n", a[c]);
 
  return 0;
}
output:
enter the number of elements in array
3
enter the array elements
508
519
1596
reverse array is 
1596
519
508
flag   
   add comment

Your answer

Join with account you already have

FF

Preview


Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!

Alert