D
devoreband
What change shuld i make to my code so that the largest value stored
in a is displayed first, followed by the
second largest value, then the third, and so forth (i.e. the cout at
Line 35 displays the values stored
in a in descending order)?
13 void f1(int a[]) {
14 int x, y;
15 int t;
16 for(x = 1; x < 10; x++) {
17 if(a[x] = a[x - 1]) {
18 t = a[x];
19 y = x;
20 do {
21 a[y] = a[y - 1];
22 y--;
23 } while (y > 0 && a[y - 1] > t);
24 a[y] = t;
25 }
26 }
27 return;
28 }
29 int main (int argc, char **argv)
30 {
31 int a[10];
32 char reply;
33 for (int i = 0; i < 10; i++) a = 100 - i;
34 f1(a);
35 for (int i = 0; i < 10; i++) cout << i << ". " << a << endl;
in a is displayed first, followed by the
second largest value, then the third, and so forth (i.e. the cout at
Line 35 displays the values stored
in a in descending order)?
13 void f1(int a[]) {
14 int x, y;
15 int t;
16 for(x = 1; x < 10; x++) {
17 if(a[x] = a[x - 1]) {
18 t = a[x];
19 y = x;
20 do {
21 a[y] = a[y - 1];
22 y--;
23 } while (y > 0 && a[y - 1] > t);
24 a[y] = t;
25 }
26 }
27 return;
28 }
29 int main (int argc, char **argv)
30 {
31 int a[10];
32 char reply;
33 for (int i = 0; i < 10; i++) a = 100 - i;
34 f1(a);
35 for (int i = 0; i < 10; i++) cout << i << ". " << a << endl;