2. Mr. Raju want to read 10 array elements and wants to display them in the reverse way. Write a C
program to help Mr. Raju to display the array elements in the reverse way
#include <stdio.h>
int main()
{
printf("Enter the number of array elements: ");
int n;
scanf("%d",&n);
int arr[n];
printf("\nEnter elements of the array:\n");
for(int i=0;i<n;i++){
scanf("%d",&arr[i]);
}
//print original array
printf("\nOriginal array:\n");
for(int i=0;i<n;i++){
printf("%d ",arr[i]);
}
//print reversed array
printf("\nReversed array:\n");
for(int i=(n-1);i>=0;i--){
printf("%d ",arr[i]);
}
return 0;
}
Comments
Leave a comment