Write a program that first reads at most 30 numbers of type
Solution
Please follow the code and comments for description :
CODE :
#include <stdio.h> // required header files
 #include <unistd.h>
 #include <stdlib.h>
void printReverse(double *d, double *newArray, int n) { // function to print the reverse array
 int i;
 int j; // local variables
 int count = 0;
printf(\"The array in reverse Order (5 values per line) is : \ \");
 for (i = 0, j = n - 1; i < n; i++, j--) { // iterate over the nodes
 newArray[i] = d[j]; // assign data to new array
 if (abs(newArray[i]) != 0) { // check for the value
 count++; // increment the count
 printf(\"%0.2lf\\t\", newArray[i]); // print the data
 if (count % 5 == 0) { // check for new line count
 printf(\"\ \");
 }
 } else {
 continue;
 }
 }
 }
int main() { // driver method
double array[30]; // array to store the data
printf(\"Enter array elements:\ \"); // message
for (int i = 0; i < 30; i++) { // iterate to get the data
 if (scanf(\"%lf\", &array[i]) == \'q\') {
 break;
 }
 }
 size_t n = sizeof (array) / sizeof (double); // get the size of the data
 double newArr[n];
 printReverse(array, newArr, n); // call the function
 }
 OUTPUT :
Enter array elements:
 -132
 -5.6
 8
 9
 9.3
 6.4
 7.8
 20
 -96.4
 -6845.1
 quit
 The array in reverse Order (5 values per line) is :
 -6845.10 -96.40 20.00 7.80 6.40
 9.30 9.00 8.00 -5.60 -132.00
Hope this is helpful.


