Changing code for to be able to change the variable...???

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;
 
I

Ian Collins

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)?
Come on, at least make an attempt. This isn't a homework group.
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;
 
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)?

Come on, at least make an attempt. This isn't a homework group.






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;



this is the first question i posted on the forum man what are you
talking about. I am trying to learn something i dont ask you to give
the answer but at least you can tell me what to o to figure out the
problem right? if you dont want to do it, it is cool too; but i am not
trying to get my homeworks done...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top