arranging an array in ascending order

Discussion in 'C Programming' started by Chitransh, Dec 30, 2011.

  1. Chitransh

    Chitransh

    Joined:
    Dec 30, 2011
    Messages:
    1
    #include<iostream.h>
    #include<conio.h>
    void main()
    {
    int c[5]={4,7,9,8,1};
    int i,j,k,temp,n;
    int min=3;
    for(j=0;j<5;j++)
    {
    for(i=j;i<5;i++)
    {
    if(c<min)
    {
    min=c;
    }
    }
    for(k=0;k<5;k++)
    {
    if(min==c[k])
    {
    temp=c[k];
    c[k]=c[j];
    c[j]=temp;
    }
    }
    }
    for(n=0;n<5;n++)
    cout<<c[n];
    getch();
    }
    //i tried to use this program for arranging elements in ascending order in an array...it does not give the desired output...pls tell me the reason
    Chitransh, Dec 30, 2011
    #1
    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. =?Utf-8?B?Sm9l?=
    Replies:
    2
    Views:
    607
    =?Utf-8?B?RGVhc3Vu?=
    Nov 19, 2004
  2. fred_stevens@hotmail.com

    Sorting a vector in ascending order

    fred_stevens@hotmail.com, Mar 3, 2005, in forum: C Programming
    Replies:
    0
    Views:
    293
    fred_stevens@hotmail.com
    Mar 3, 2005
  3. fred_stevens@hotmail.com

    Sorting a vector in ascending order

    fred_stevens@hotmail.com, Mar 3, 2005, in forum: C Programming
    Replies:
    2
    Views:
    287
    fred_stevens@hotmail.com
    Mar 4, 2005
  4. PRadyut
    Replies:
    2
    Views:
    477
    Barry Schwarz
    Jun 10, 2005
  5. sudhir
    Replies:
    8
    Views:
    819
    Kenny McCormack
    Dec 6, 2005
Loading...

Share This Page