Solved

# How to arrange a group of integer variables in ascending order

Posted on 2012-03-21
667 Views
I have three integer values,
intFlop1
intFlop2
intFlop3

These need to be arranged in ascending order by value.

intFlop1 = 9;
intFlop2 = 13;
intFlop3 = 11;

It is sufficient to determine the max and min values. The middle value can be deduced.

I could do this by using nested if statements. Is there a more efficient way?

Thanks,
0
Question by:Dovberman
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 5

Assisted Solution

Aruiz04 earned 100 total points
ID: 37750267
with the help of Linq
using system.Linq;
``````int intFlop1 = 9; int intFlop2 = 13; int intFlop3 = 11;
int[] intArr = { intFlop1, intFlop2, intFlop3 };
IEnumerable<int> intOrdered = from o in intArr orderby o select o;

foreach (int i in intOrdered)
{
Response.Write(i.ToString() + "<BR>");
}
``````
0

LVL 16

Accepted Solution

Rose Babu earned 400 total points
ID: 37756033
Hi,

you may use the array to hold the int values and array.sort method to sort the data.
``````	int intFlop1 = 12;
int intFlop2 = 10;
int intFlop3 = 9;

int[] arrayIntFlop = { intFlop1, intFlop2, intFlop3 };

Array.Sort(arrayIntFlop);

int[] arraySorted = arrayIntFlop;
``````
Try this. It will work for you.
0

Author Closing Comment

ID: 37756386
Thank you.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Six Sigma Control Plans
###### Suggested Courses
Course of the Month6 days, 12 hours left to enroll