Write a code fragment that reverses the order of the values in a one-dimensional string array. Do not create another array to hold the result. Hint: Use the code in the text for exchanging the values of two elements.. Implement using a while loop
#include <stdio.h>
int main()
{
int arr[] = {1, 2, 3, 4, 5, 6};
int n = 6,start=0;
int end=n-1;
printf("Before Reverse: \n");
for (int i = 0; i < n; i++)
printf("%d ",arr[i]);
printf("\n");
while (start < end)
{
// swapping the fist and last elements
int temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
}
printf("Before Reverse: \n");
for (int i = 0; i < n; i++)
printf("%d ",arr[i]);
return 0;
}
Note : If you like my answer please rate and help me it is very Imp for me
Get Answers For Free
Most questions answered within 1 hours.