943,960 Members | Top Members by Rank

Ad:
Aug 2nd, 2009
0

How do I get the highest and lowest of an array?

Expand Post »
Guys, Im in desperately need of help, and I need the whole program to be written, as I dont understand anythuing in pascal haha.
Thanks for any help, I really appreciate it!
By the way, this is also my first post here, yay
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
satasonic is offline Offline
2 posts
since Aug 2009
Aug 2nd, 2009
0

Re: How do I get the highest and lowest of an array?

Hi satasonic
In pascal there are two functions like Low() and High()
pascal Syntax (Toggle Plain Text)
  1.  
  2. Program LowAndHigh;
  3. Uses Crt;
  4. Var MyArray:Array[0..124]Of Byte;
  5. Begin
  6. ClrScr;
  7. {min value:Low function}
  8. WriteLn('Minimum value of MyArray: ',Low(MyArray));
  9. {max value:High function}
  10. WriteLn('Maximum value of MyArray: ',High(MyArray));
  11. ReadLn;
  12. End.
  13. {Written by FlamingClaw}
Reputation Points: 132
Solved Threads: 138
Posting Pro
FlamingClaw is offline Offline
559 posts
since Feb 2009
Aug 2nd, 2009
0

Re: How do I get the highest and lowest of an array?

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
satasonic is offline Offline
2 posts
since Aug 2009
Aug 2nd, 2009
0

Re: How do I get the highest and lowest of an array?

Click to Expand / Collapse  Quote originally posted by satasonic ...
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
Of course this is the whole program.
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.
Reputation Points: 132
Solved Threads: 138
Posting Pro
FlamingClaw is offline Offline
559 posts
since Feb 2009
Aug 2nd, 2009
0

Re: How do I get the highest and lowest of an array?

I wonder, High and Low return the highest and lowest array index iirc. Isn't he looking for Min and Max ?
Sponsor
Featured Poster
Reputation Points: 550
Solved Threads: 731
Bite my shiny metal ass!
pritaeas is offline Offline
4,177 posts
since Jul 2006
Aug 3rd, 2009
0

Re: How do I get the highest and lowest of an array?

Click to Expand / Collapse  Quote originally posted by pritaeas ...
I wonder, High and Low return the highest and lowest array index iirc. Isn't he looking for Min and Max ?
If you try my code (just copy and paste) ,you will see the results low as 0 and high as 124,the type of byte's range is 0..255
But he want to know the max range of byte type then
pascal Syntax (Toggle Plain Text)
  1. Program Solution;
  2. Uses Crt;
  3. Var my:Array[Byte]Of Byte;
  4. Begin
  5. ClrScr;
  6. WriteLn(High(my));
  7. ReadLn;
  8. End.
  9. {the result is 255}
Last edited by FlamingClaw; Aug 3rd, 2009 at 12:19 pm.
Reputation Points: 132
Solved Threads: 138
Posting Pro
FlamingClaw is offline Offline
559 posts
since Feb 2009
Aug 3rd, 2009
0

Re: How do I get the highest and lowest of an array?

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.
Reputation Points: 9
Solved Threads: 2
Newbie Poster
TeejMonster is offline Offline
19 posts
since Jul 2009
Aug 4th, 2009
0

Re: How do I get the highest and lowest of an array?

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.
And it will look like this (for getting the minimum value):
pascal Syntax (Toggle Plain Text)
  1. var
  2. MinValue, I: Integer;
  3.  
  4. for I:= Low(MyArray) to High(MyArray) do
  5. begin
  6. if I = Low(MyArray) then MinValue:= MyArray[I] else
  7. if MyArray[I] < MinValue then MinValue:= MyArray[I];
  8. end;

Sincerely,
Tom Barnett
SNIP
Last edited by happygeek; Aug 5th, 2009 at 6:55 am. Reason: fake sig url snipped
Reputation Points: 13
Solved Threads: 0
Newbie Poster
Tom Barnett is offline Offline
4 posts
since Sep 2008
Aug 10th, 2009
0

Re: How do I get the highest and lowest of an array?

When I was a beginer, I was doing random problems in Pascal. Here is one that might help you...

pascal Syntax (Toggle Plain Text)
  1. uses
  2. crt;
  3. var
  4. i, control : longint;
  5. input, sum : real;
  6. begin
  7. writeln('Enter the total number of inputs. Then, enter them one by one until you see an output.');
  8. readln(control);
  9. sum := -1000000;
  10. for i := 1 to control do
  11. begin
  12. readln(input);
  13. if input >= sum then
  14. begin
  15. sum := input;
  16. end;
  17. end;
  18. writeln(sum:0:4);
  19. readln;
  20. 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!!
Reputation Points: 76
Solved Threads: 6
Junior Poster
djextreme5 is offline Offline
103 posts
since Mar 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Pascal and Delphi Forum Timeline: TComboBox -> csDropDownList - Select by Value?
Next Thread in Pascal and Delphi Forum Timeline: TComPort4Beta and delphi2009





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC