Write a C program to find the reverse of an array, In this C program example, we will see how to find the reverse of an array by using for loop.
Sample input
enter the size of an array: 5
enter elements:
2
5
6
3
1
Sample output
13652
Algorithm to find reverse of an array
- Declare an array and two variables.
- Then take two inputs first for the size of the array and another loop for taking elements.
- Take two for loop first for input and the second one for the print reverse array.
C program to find reverse of an array
#include<stdio.h> void main (){ int arr[10],n,i; printf("enter the size of an array"); scanf("%d",&n); printf( "enter elements:\n",n); for(i=0;i<n;++i){ scanf("%d",&arr[i]); } for(i=n-1;i>=0;--i){ printf("%d",arr[i]); } }
Explanation of this c program
Step 1: Sart.
Step 2: Create a header file and in the hadder file include a library.
Step 3: Then, create a void main function.
Step 4: Declare an array (arr[10]) and two variables (i and n).
Step 5: Create two inputs, first for the size of an array and the other in the loop for taking elements from a user taking input with the help of scanf.
Step 6: Create two for loop, one for the input of elements and the second for print the reverse array.
Step 7: Give the condition, increment, and decrement in for loop.
Step 8: End.
Output
In this way, we learned how to write a C program to find the reverse of an array