Write a program in C to read n number of values in an array and display it in reverse order.
- Start the program.
- Declare an integer variable n to store the size of the array.
- Read the value of n from the user using scanf.
- Declare an integer array of size n.
- Use a for loop from 0 to n-1 to read n elements into the array using scanf.
- Use another for loop from n-1 down to 0 to print the elements of the array in reverse order.
- End the program.
#include <stdio.h>
int main()
{
int n, i;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=n-1;i>=0;i--)
printf("%d ",a[i]);
return 0;
}
Thus the program to read n number of values in an array and display it in reverse order has been executed successfully