Write a program that first reads at most 30 numbers of type
Write a program that first reads at most 30 numbers of type double from the user (the user will type character quit when finished), and stores these values in an array in the same order that they were entered by the user. Your program should then call the function reverse array with this array as an argument, and finally displays the new contents of the array to the screen, 5 values per line. Sample Input/Output: (the user\'s input is shown in bold) Please enter at most 30 numbers/type quit when finished. 1396 470 -9-1 9180-5011 0 2-275 13 216 15 -7 quit The array in reverse order (5 values per line) is -715 216 13-275 2 0-5011 9180-1 -9 470 1396
Solution
Use the below piece of code :
Question2.c
#include <stdio.h>
/* Below Function will reverse arr[] from starting to ending*/
void reverseArray(int arr[], int starting, int ending)
{
int tmp;
if (starting >= ending)
return;
tmp = arr[starting];
arr[starting] = arr[ending];
arr[ending] = tmp;
reverseArray(arr, starting+1, ending-1);
}
/* Below Utility will print out an array in a line */
void printArray(int arr[], int size)
{
int i;
for (i=0; i < size; i++)
printf(\"%d \", arr[i]);
printf(\"\ \");
}
/* The Driver function which will test the function */
int main()
{
int arr[] = {5, 6, 7, 8, 9};
printArray(arr, 5);
reverseArray(arr, 0, 4);
printf(\"Reversed array is \ \");
printArray(arr, 5);
return 0;
}
