Question: Have your program print the data out three ways first is the original data, second is the data in ascending order, and second is the

Have your program print the data out three ways first is the original data, second is the data in ascending order, and second is the data in descending order. Each of these three printouts should be on a single line in columns that are four wide and with each value having an explicitly positive/negative sign and being exactly two digits long (so add a leading zero if needed). The following is what a run might look like: O: -58 +60 +66 -66 -34 -96 +36 +06 -02 +87 +34 -13 +98 +12 -88

A: -96 -88 -66 -58 -34 -13 -02 +06 +12 +34 +36 +60 +66 +87 +98

D: +98 +87 +66 +60 +36 +34 +12 +06 -02 -13 -34 -58 -66 -88 -96

#include #include #define length 15

int main(void) { int n[length]; int number = 0; printf("O: "); for(int i = 0; i < length; i++) { number = (rand() % 199) - 99; if (number < 0) { printf("%03d ", number); } else { printf("+%02d ", number); } n[i] = number; } int a[length] = { 0 }; // Will initialize all elements to 0; int temp = 0; int x = 0; int y = 0; int number2 = 0; number = 0; printf(" A: "); for(int i = 0; i < length; i++) { number = n[i]; for(int n = 0; n < length; i++) { number2 = a[n]; if (number <= number2) { x = number; y = a[n]; temp = a[n + 1]; a[n] = x; int count = length - n; for (int y = 0; y < count; y++) { if(temp != 0) { a[n + 1] = y; }else { a[n + 1] = temp; } } break; }else if (number2 == 0) { a[n] = number; break; } } } for(int i = 0; i < length; i++) { int number = a[i]; if (number < 0) { printf("%03d ", number); } else { printf("+%02d ", number); } } int d[length]; int count = 0; printf(" D: "); for(int i = 0; i < length; i++) { count += 1; int number = a[length - count]; d[i] = number; } for(int i = 0; i < length; i++) { int number = d[i]; if (number <= -1) { printf("%03d ", number); } else { printf("+%02d ", number); } } return EXIT_SUCCESS; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!