Solved

How to arrange a group of integer variables in ascending order

Posted on 2012-03-21
3
664 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

820 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