Solved

How to arrange a group of integer variables in ascending order

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

696 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