From aa54ddd2754e5541685a73c3fb054b24a5c1bfdd Mon Sep 17 00:00:00 2001 From: DareDevilStudios <81734540+DareDevilStudios@users.noreply.github.com> Date: Fri, 1 Oct 2021 22:21:49 +0530 Subject: [PATCH] Create reverse-array.c program to reverse the array --- arrays/reverse-array/reverse-array.c | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 arrays/reverse-array/reverse-array.c diff --git a/arrays/reverse-array/reverse-array.c b/arrays/reverse-array/reverse-array.c new file mode 100644 index 0000000..2dad35f --- /dev/null +++ b/arrays/reverse-array/reverse-array.c @@ -0,0 +1,30 @@ +#include + +void reverseArray(int arr[], int start, int end) // funtion to reverse the array +{ + int temp; + while (start < end) + { + temp = arr[start]; + arr[start] = arr[end]; + arr[end] = temp; + start++; + end--; + } +} + +int main() +{ + int n,i,arr[100]; + printf("\n\n\t\t Reversing the array\n\n"); + printf("Enter the limit of the array : "); + scanf("%d",&n); + printf("\nEnter the elements of the array :\n\n"); + for (int i = 0; i < n; i++) // accepting the elements + scanf("%d",&arr[i]); + reverseArray(arr, 0, n-1); // calling the function for reversing the array. + printf("Reversed array is \n"); + for (i=0; i < n; i++) + printf("%d ", arr[i]); + return 0; +}