Solved

How to arrange a group of integer variables in ascending order

Posted on 2012-03-21
3
657 Views
Last Modified: 2012-03-23
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
Comment
Question by:Dovberman
3 Comments
 
LVL 5

Assisted Solution

by:Aruiz04
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>");
        }

Open in new window

0
 
LVL 16

Accepted Solution

by:
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;

Open in new window

Try this. It will work for you.
0
 

Author Closing Comment

by:Dovberman
ID: 37756386
Thank you.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now