Solved

How to arrange a group of integer variables in ascending order

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Store results in vb.net 3 22
Question about JQuery and asp.net 3 27
MVC DDL Json Not Binding to Model 2 13
Convert datetime to time string 10 21
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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…

803 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