By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,303 Members | 1,590 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,303 IT Pros & Developers. It's quick & easy.

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

P: n/a
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[i] = 100 - i;
34 f1(a);
35 for (int i = 0; i < 10; i++) cout << i << ". " << a[i] << endl;

Mar 22 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
de********@gmail.com wrote:
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[i] = 100 - i;
34 f1(a);
35 for (int i = 0; i < 10; i++) cout << i << ". " << a[i] << endl;

--
Ian Collins.
Mar 22 '07 #2

P: n/a
On Mar 22, 4:32 pm, Ian Collins <ian-n...@hotmail.comwrote:
devoreb...@gmail.com wrote:
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[i] = 100 - i;
34 f1(a);
35 for (int i = 0; i < 10; i++) cout << i << ". " << a[i] << endl;

--
Ian Collins.- Hide quoted text -

- Show quoted text -
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...

Mar 22 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.