Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions arrays/reverse-array/reverse-array.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include<stdio.h>

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;
}