How to sort?

Hi i need to create a program that will accept 10 numbers as input. Output the list of numbers in numerical order. I have it to were i can accept 10 numbers but when it outputs the list it does it in reverse order.


#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
int num[10];
int i;
for (i=0;i<10;i++)
{
cout << "Enter Number:";
cin >> num[i];
}
for (i=9;i>=0;i--)
{
cout << num[i] << endl;
}
system("PAUSE");
return 0;
}
Last edited on
change your second for loop

from
for (i=9;i>=0;i--)
to
for (i=0; i < 10; i++)
that changed the reverse order put it still didn't put the numbers in numerical order, say if i entered the numbers like 1,3,5,6,7,2,8,10,9 it should put them in order.
you need to write some code to compare them to put them in that order. All that you are doing is going through the same list they typed and displaying it again.

You have two options. 1. Sort the numbers as they are typed or 2. sort them when they are being displayed. Or I guess there may be a sort function that you can call to do it for you.
do
sort (num, num+8)
that will sort your number values. But this is just in the beginning. Look upffor sorting algorithms in the internet and learn to sort using those algorithms,
Bubble sort is the easiest to learn in my opinion
where do i put sort (num, num+8)?
after you have filled the values of the array
Topic archived. No new replies allowed.