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

Discussion in 'C++' started by devoreband@gmail.com, Mar 22, 2007.

  1. Guest

    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;
     
    , Mar 22, 2007
    #1
    1. Advertising

  2. Ian Collins Guest

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



    --
    Ian Collins.
     
    Ian Collins, Mar 22, 2007
    #2
    1. Advertising

  3. Guest

    On Mar 22, 4:32 pm, Ian Collins <> wrote:
    > 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 = 100 - i;
    > > 34 f1(a);
    > > 35 for (int i = 0; i < 10; i++) cout << i << ". " << a << 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, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pankaj Jain
    Replies:
    1
    Views:
    345
    Daniel Fisher\(lennybacon\)
    Nov 30, 2005
  2. Protoman
    Replies:
    28
    Views:
    802
    Protoman
    Jul 5, 2007
  3. rahul
    Replies:
    0
    Views:
    275
    rahul
    Apr 27, 2009
  4. rahul
    Replies:
    2
    Views:
    291
    Gabriel Genellina
    Apr 27, 2009
  5. sed_y
    Replies:
    0
    Views:
    1,064
    sed_y
    Feb 15, 2012
Loading...

Share This Page