Answer:
The program to this question as follows:
Program:
#include <stdio.h> //header file.
int main() //main method.
{
const int size= 20; //define variable.
int a[size]; //define array
int i, n; //define variable
printf("Enter number of elements :"); //message.
scanf("%d", &n);//input size of array.
printf("Enter array elements :"); //message
for (i = 0; i < n; ++i) //loop
{
scanf("%d",&a[i]); //input array elements by user.
}
printf("Reverse order :\n");
for (i = 0; i < n; ++i) //loop
{
printf("%d ",a[n-i-1]); //print elements in reverse order.
}
return 0;
}
Output:
Enter number of elements :5
Enter array elements :5
4
3
2
1
Reverse order :
1 2 3 4 5
Explanation:
The description of the above program as follows:
- In the program firstly we include the header file and define a method that is "main method" in the method we define variables that are "size, n, i, and a[]". The size variable is used to make a variable constant that means its value will not change in the program. We pass the size variable value to the array and use i variable for loop.
-
We use variable n and a[] for user inputs. In n variable, we input a number of elements to be inserted into an array and a[] we insert all array elements to insert these elements we use for loop.
-
Then we define another for loop in this loop we print all array elements in reverse order.