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

Printing Numbers in Ascending Order

P: 2
Hi Everyone,

I am trying to create a program that arranges numbers in ascending order. I do not understand how to do this.

To start, think that I would need to include several if and else if statements coming values. Than I would use the operators ">" and "<" to compare the int values I have already declared. Could someone explain how to do this?

Thanks in advance.
Feb 25 '07 #1
Share this Question
Share on Google+
4 Replies


Ganon11
Expert 2.5K+
P: 3,652
How will the numbers be stored? Will the be in an array or some other data structure?
Feb 25 '07 #2

P: 2
How will the numbers be stored? Will the be in an array or some other data structure?
Umm. I'm really not sure. I am declaring them as "int." Is this what you mean?
Feb 25 '07 #3

Ganon11
Expert 2.5K+
P: 3,652
Well, I gathered they would be ints, but in order to sort them, I assumed you had to store them somewhere. How exactly are you supposed to get these numbers, and when will they be sorted?
Feb 25 '07 #4

P: 2
You should use any data structure like array etc..you get numbers in array,and use the logic like
int[] a = new int[5] { 4, 2, 6, 1, 5 };
int temp;
for (int i = 0; i <4; i++)
{
for (int j = 1; j <= 4; j++)
{
if (a[i] > a[j])
{
temp = i;
i = j;
j = temp;
}
}
Console.WriteLine("ASCENDING : {0}", a[i]);
}
Oct 17 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.