Article View: comp.lang.modula2
Article #3289Modula-2 to Pascal
From: Matt Garrett
Date: Sat, 17 Feb 1996 04:49
Date: Sat, 17 Feb 1996 04:49
76 lines
2676 bytes
2676 bytes
This is a multi-part message in MIME format.
--------------42428DA7AE3
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
This is a program written in modula-2 and it needs to be converted into
pascal i need this by sunday 2-18-95! Thanks this is for a science fair
project!
--------------42428DA7AE3
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="Matt.pas"
PROGRAM timeit;
(* Illustrates use of the TimeDate module to compare iterative and recursive *)
(* fibonacci functions. T.W. 1-20-91; March 1995 *)
FROM IO IMPORT RdlngCard, WrLngCard, WrStr, WrChar, WrLn;
FROM TimeDate IMPORT ZeroTime, StartTime, StopTime, TellTime;
CONST RepeatFactor = 1000;
VAR i, N, F: LONGCARD;
PROCEDURE FiboI(N: LONGCARD):LONGCARD;
(* Returns the Nth Fibonacci. Interative. *)
VAR a,b,c,k: LONGCARD;
BEGIN
IF (N = 0) OR (N = 1) THEN
RETURN 1
ELSE
a := 1;
b := 1;
FOR k := 2 TO N DO
c := a + b;
a := b;
b := c;
END;
RETURN c
END;
END FiboI;
PROCEDURE FiboR(N: LONGCARD) :LONGCARD;
(* Returns the Nth Fibonacci. Recursive. *)
BEGIN
IF (N = 0) OR (N = 1) THEN
RETURN 1
ELSE
RETURN FiboR(N-1) + FiboR(N-2)
END;
END FiboR;
BEGIN
Wrln; WrStr('Computing the Nth Fibonacci. Enter N. ');
N := RdLngCard();
ZeroTime;
StartTime;
F := FiboR(N);
StopTime;
WrLn; WrStr('The value is '); WrLngCard(F, 5); WrChar('.');
WrLn; WrStr('Elapsed time (recursively): '); TellTime;
ZeroTime;
FOR i := 1 TO RepeatFactor DO
StartTime;
F := FiboI(N) ;
StopTime;
END;
WrLn; WrStr('The value is '); WrLngCard(F, 5); WrChar('.');
WrLn; WrStr('Elapse time * '); WrLngCard(RepeatFactor,0);
WrStr(' (iteratively): ');
TellTime;
END timeit.
--------------42428DA7AE3--
Technical Details
Message-ID:
<31255E6B.71A7@mo.net>Path:
arc1-ca.pugleaf.net!News.MO.NET!usenetShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!News.MO.NET!usenet From: Matt Garrett <mattgt@mo.net> Newsgroups: comp.lang.modula2 Subject: Modula-2 to Pascal Date: Fri, 16 Feb 1996 22:49:47 -0600 Organization: -=MO.NET=- MVP-Net, Inc's Missouri Operations Message-ID: <31255E6B.71A7@mo.net> NNTP-Posting-Host: pm3x2.dialip.mo.net Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------42428DA7AE3" X-Mailer: Mozilla 2.0 (Win95; I)