Thread View: comp.lang.modula2
3 messages
3 total messages
Started by Matt Garrett
Sat, 17 Feb 1996 04:49
Modula-2 to Pascal
Author: 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--
Re: Modula-2 to Pascal
Author: "Mark Morgan Lloyd "
Date: Sat, 17 Feb 1996 14:24
Date: Sat, 17 Feb 1996 14:24
7 lines
494 bytes
494 bytes
So what's the problem? Mark Morgan Lloyd mark_tbu@cix.compulink.co.uk [Opinions above are the author's, not those of his employers or colleagues]
Re: Modula-2 to Pascal
Author: j.w.kalkman
Date: Mon, 19 Feb 1996 17:28
Date: Mon, 19 Feb 1996 17:28
22 lines
1147 bytes
1147 bytes
In article <31255E6B.71A7@mo.net> Matt Garrett <mattgt@mo.net> writes: >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! Then it's time you learn that "science" does not equal "let someone else do it". -- Jurriaan W Kalkman - j.w.kalkman@student.utwente.nl Now I see what I must see - the poor do time the rich go free You keep the faith and they keep score - is this what you are working for Big Country "What are you working for" - The Buffalo Skinners
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads