write a C program to accept a 1D array from the user and display the reversed array. eg. original array:10 20 30 40 50. reversed array:50 40 30 20 10. Note: create another array by assigning elements of first array in reverse order.
Answers
Answered by
3
Answer:
#include <stdio.h>
int main(){
int count;
printf("How many elements in the array:");
scanf("%d" , &count);
int arr[count];
printf("Enter all %d elements in the array: \n" , count);
for(int i = 0; i < count; i++){
scanf("%d" , &arr[i]);
}
printf("---ORIGINAL ARRAY--- \n");
for(int i = 0; i < count; i++){
printf("%d " , arr[i]);
}
int reversed[count];
int j = count;
for(int i = 0; i < count; i++){
reversed[j-1] = arr[i];
j--;
}
printf("\n");
printf("--REVERSED ARRAY---\n");
for(int i = 0; i < count; i++){
printf("%d " , reversed[i]);
}
return 0;
}
Explanation:
Similar questions