| | |
How do I get the highest and lowest of an array?
Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
![]() |
Hi satasonic
In pascal there are two functions like Low() and High()
In pascal there are two functions like Low() and High()
pascal Syntax (Toggle Plain Text)
Program LowAndHigh; Uses Crt; Var MyArray:Array[0..124]Of Byte; Begin ClrScr; {min value:Low function} WriteLn('Minimum value of MyArray: ',Low(MyArray)); {max value:High function} WriteLn('Maximum value of MyArray: ',High(MyArray)); ReadLn; End. {Written by FlamingClaw}
Be a good part of the community.Don't be ungrateful.
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
•
•
•
•
Is this the whole program? I put it in and it didnt seem to work, when I typed a number it just minimized.
Sorry, but im really stupid in Pascal lol
Contains an array and two functions's calling.
And it is working
I wrote my program in dev pascal 1.9.2.It is a free pascal compiler,support (almost) every commands of the Turbo Pascal 7.0,and 100% free pascal compatible and it is free....
Last edited by FlamingClaw; Aug 2nd, 2009 at 4:20 am.
Be a good part of the community.Don't be ungrateful.
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
•
•
•
•
I wonder, High and Low return the highest and lowest array index iirc. Isn't he looking for Min and Max ?

But he want to know the max range of byte type then
pascal Syntax (Toggle Plain Text)
Program Solution; Uses Crt; Var my:Array[Byte]Of Byte; Begin ClrScr; WriteLn(High(my)); ReadLn; End. {the result is 255}
Last edited by FlamingClaw; Aug 3rd, 2009 at 12:19 pm.
Be a good part of the community.Don't be ungrateful.
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
So we can help a little better, could clarify what you need a little?
Do you need the highest and lowest VALUE in the array? What type of array are you using (integer, float, etc)? How should the program receive the array?
If you decide to take a whack at it yourself (and you're looking for min max values), you'll basically want to have a program that starts with two variables "MIN" and "MAX". Set them both to the first value in your array. Then loop through the array, comparing each number to min and max. If a number is less than the value in MIN, set MIN to that number. If a number is greater than MAX, set MAX to that number.
Do you need the highest and lowest VALUE in the array? What type of array are you using (integer, float, etc)? How should the program receive the array?
If you decide to take a whack at it yourself (and you're looking for min max values), you'll basically want to have a program that starts with two variables "MIN" and "MAX". Set them both to the first value in your array. Then loop through the array, comparing each number to min and max. If a number is less than the value in MIN, set MIN to that number. If a number is greater than MAX, set MAX to that number.
•
•
Join Date: Sep 2008
Posts: 4
Reputation:
Solved Threads: 0
•
•
•
•
If a number is less than the value in MIN, set MIN to that number. If a number is greater than MAX, set MAX to that number.
pascal Syntax (Toggle Plain Text)
var MinValue, I: Integer; for I:= Low(MyArray) to High(MyArray) do begin if I = Low(MyArray) then MinValue:= MyArray[I] else if MyArray[I] < MinValue then MinValue:= MyArray[I]; end;
Sincerely,
Tom Barnett
SNIP
Last edited by happygeek; Aug 5th, 2009 at 6:55 am. Reason: fake sig url snipped
When I was a beginer, I was doing random problems in Pascal. Here is one that might help you...
I also have a program that find the minimum of the given input. But, I'll leave that and the array part for you to work out. After all, I shouldn't have to all the work.
Good luck!!
pascal Syntax (Toggle Plain Text)
uses crt; var i, control : longint; input, sum : real; begin writeln('Enter the total number of inputs. Then, enter them one by one until you see an output.'); readln(control); sum := -1000000; for i := 1 to control do begin readln(input); if input >= sum then begin sum := input; end; end; writeln(sum:0:4); readln; end.
I also have a program that find the minimum of the given input. But, I'll leave that and the array part for you to work out. After all, I shouldn't have to all the work.

Good luck!!
![]() |
Similar Threads
- Displaying lowest/highest in an Array? (C++)
- how to find highest and lowest number.. (C++)
- Highest and Lowest (C++)
- calculating sum, average, highest and lowest grades (Visual Basic 4 / 5 / 6)
- How can I get Highest, Lowest and Average ? (C++)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: TComboBox -> csDropDownList - Select by Value?
- Next Thread: TComPort4Beta and delphi2009
Views: 755 | Replies: 8
| Thread Tools | Search this Thread |
Tag cloud for Pascal and Delphi





