My friend has challenged me to create a simple c++ program. I have had the last 3 weeks to work on it, half way through I have realised I am doing it wrong. The program is: Entering 10 random numbers into an array( the easy part ), then printing the array in ascending order WITHOUT sorting the array. I am absolutely lost on how to do this. Can anyone give me some help with this, maybe posting some code up and I can look at it then type my own out so I am learning in the process. I really want to prove my friend wrong :lol: Any comments would be much appreciated!

P.s I have only been doing c++ for the last 6 weeks and I love it so far, so please excuse me for sounding silly :)

http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
see this link it 'll help u
u can type also ur Q there and ask about sorting.
i'm trying also 2 write the code for u.
i'll test it and send it later

Thanks man. That link is pretty useful but still not sure on what path I should be heading down. Any luck on the code you wrote? Even if its buggy, im still willing to work through it but im just not sure how I should go about it. Anychance you could post the code up? That would be hugely appreciated :)

Well this is practically doing it all for you anyway, so what the hell.

Once you've done my previous suggestion, then do
for ( i = max ; i >= min ; i-- ) for ( j = 0 ; j < n ; j++ ) if ( a[j]==i )....

> Thats sorting the array isnt it?
No, just a hugely expensive way of printing them out in order - just like you asked.

Now put all that together and post your latest attempt at solving this problem.

Ahok I have just realised a huge mistake ive been making. I wasnt thinking about using any othe variables than the array, having a Min and Max variable makes the whole process more straight forward, I will post some code up once I have it working, cheers for the help :)

int i,max,min;
int arr[10];

max=0;
min=0;

for(i=0;i<10;i++)
{
if (arr>max)
max=arr;
}


for(i=0;i<10;i++)
{
if(arr<min)
min=arr;
}

This article has been dead for over six months. Start a new discussion instead.