Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4095
Number of posts: 14004

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
function call Posted by mondenkind11 on 5 Nov 2004 at 10:13 AM
Hi...
I had the following question.
I have a program findmax, that should determine recursively the maximum in an array. How can I call the function max correctly, so that I have the maximum of the array appearing on the screen?
I would appreciate any advice. Thank you in advance.

program findmax(input, output);

type
tIndex = 0..10;
tArray = array[tIndex] of integer;

const
Array : tArray = (1, 2, 3, 6, 3, 5, 9, 4 ,4 , 2, 1);

var
low,
high : integer;


function max(var inArray : tArray;
inLow,
inHigh : tIndex): integer;


var
middle : tIndex;
maxleft,
maxright : integer;

begin
if inLow = inHigh then
max := inArray[inLow]
else
begin
middle := (inLow + inHigh) div 2;
maxleft := max(inArray, inLow, middle);
maxright := max(inArray, middle+1, inHigh);
if maxleft > maxright then
max := maxleft
else
max := maxright
end
end;

begin

{????????}
readln

end.


Thread Tree
mondenkind11 function call on 5 Nov 2004 at 10:13 AM
zibadian Re: function call on 5 Nov 2004 at 12:00 PM
mondenkind11 Re: function call on 6 Nov 2004 at 9:29 AM
Manning Re: function call on 6 Nov 2004 at 11:38 AM
mondenkind11 Re: function call on 7 Nov 2004 at 9:09 AM



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.