?
Solved

How to arrange a group of integer variables in ascending order

Posted on 2012-03-21
3
Medium Priority
?
672 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
[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
  • Learn & ask questions
3 Comments
 
LVL 5

Assisted Solution

by:Aruiz04
Aruiz04 earned 400 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 1600 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

770 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