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

Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2009
Posts: 2
Reputation: satasonic is an unknown quantity at this point 
Solved Threads: 0
satasonic satasonic is offline Offline
Newbie Poster

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

 
0
  #1
Aug 2nd, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 473
Reputation: FlamingClaw will become famous soon enough FlamingClaw will become famous soon enough 
Solved Threads: 114
FlamingClaw's Avatar
FlamingClaw FlamingClaw is offline Offline
Posting Pro in Training

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

 
0
  #2
Aug 2nd, 2009
Hi satasonic
In pascal there are two functions like Low() and High()
  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}
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...
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 2
Reputation: satasonic is an unknown quantity at this point 
Solved Threads: 0
satasonic satasonic is offline Offline
Newbie Poster

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

 
0
  #3
Aug 2nd, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 473
Reputation: FlamingClaw will become famous soon enough FlamingClaw will become famous soon enough 
Solved Threads: 114
FlamingClaw's Avatar
FlamingClaw FlamingClaw is offline Offline
Posting Pro in Training

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

 
0
  #4
Aug 2nd, 2009
Originally Posted by satasonic View Post
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.
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...
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 883
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 144
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark

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

 
0
  #5
Aug 2nd, 2009
I wonder, High and Low return the highest and lowest array index iirc. Isn't he looking for Min and Max ?
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 473
Reputation: FlamingClaw will become famous soon enough FlamingClaw will become famous soon enough 
Solved Threads: 114
FlamingClaw's Avatar
FlamingClaw FlamingClaw is offline Offline
Posting Pro in Training

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

 
0
  #6
Aug 3rd, 2009
Originally Posted by pritaeas View Post
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
  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.
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...
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 18
Reputation: TeejMonster is an unknown quantity at this point 
Solved Threads: 1
TeejMonster's Avatar
TeejMonster TeejMonster is offline Offline
Newbie Poster

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

 
0
  #7
Aug 3rd, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 4
Reputation: Tom Barnett is an unknown quantity at this point 
Solved Threads: 0
Tom Barnett Tom Barnett is offline Offline
Newbie Poster

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

 
0
  #8
Aug 4th, 2009
Originally Posted by TeejMonster View Post
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):
  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
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 66
Reputation: djextreme5 is on a distinguished road 
Solved Threads: 4
djextreme5's Avatar
djextreme5 djextreme5 is offline Offline
Junior Poster in Training

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

 
0
  #9
Aug 10th, 2009
When I was a beginer, I was doing random problems in Pascal. Here is one that might help you...

  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!!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 755 | Replies: 8
Thread Tools Search this Thread



Tag cloud for Pascal and Delphi
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC