Hey,
Im having a problem with sorting numbers. I want to sort 4 numbers in orders of size i.e. if the order is 5,8,9,2 I would like it to distinguish the highest number (which in this case would be 9) and lowest (2). Could someone suggest how i would go about doing this. Ive declared each number as num1, num2, num3, num4 and declared both the highestNum and lowestNum. If someone could show any way of doing thsi be it an if statement or array i'd be extremely greatfull.
-Flipz-
0
Newbie Poster
Recommended Answers
Jump to PostInstead of declaring each number in a separate variable, you should use an array to store the numbers. Once you have them in an array, you then need to decide on a sorting method. There are many sorting algorithms:
Jump to PostYeah simple bubble sort
Define an array [] of integers
Define a counter , lets say its called 'i'Use a for loop with another loop nested in it
e.g For (i = 0; i<Size of array; i++)
what this means is start the counter at …
Jump to PostEven better solution is to use Array.Sort in the .NET.
Declare an integer array, put your numbers there call sort methodDim IntArr(3) As Integer IntArr(0) = 5 IntArr(1) = 8 IntArr(2) = 9 IntArr(3) = 2 Array.Sort(IntArr)
Sort method sorts in the ascending order. To get …
All 10 Replies
timothybard
12
Posting Whiz
jbennet
1,618
Most Valuable Poster
Team Colleague
Featured Poster
Teme64
215
Veteran Poster
-Flipz-
0
Newbie Poster
isaackhazi
0
Newbie Poster
jbennet
1,618
Most Valuable Poster
Team Colleague
Featured Poster
Teme64
215
Veteran Poster
jbennet
1,618
Most Valuable Poster
Team Colleague
Featured Poster
isaackhazi
0
Newbie Poster
isaackhazi
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.