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?
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?
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]);
}