home *** CD-ROM | disk | FTP | other *** search
- {TURUN -- A sample program written in Tiny Pascal }
- var I, J, K, PROBLEM;
-
- {*********************}
- function ISLESS(N1, N2);
- begin {returns 1 if n1<n2, 0 otherwise}
- if n2-n1 then isless:=1 {truth value test is >0}
- else isless:=0;
- end;
-
- function ADDEMUP(LOWER, UPPER, SUM);
- begin end; {makes it a forward declaration}
-
- {*********************}
- function ISEQUAL(N1, N2);
- begin
- if n2-n1 then isequal:=0 {false}
- else
- if n1-n2 then isequal:=0
- else isequal:=1;
- end;
-
- {***********************}
- function ADDEMUP(LOWER, UPPER, SUM);
- {SUM is a local}
- begin
- sum:=0;
- while isless(lower, upper) do begin
- sum:=sum+lower;
- lower:=lower+1;
- end;
- addemup:=sum+lower; { the last one was left out }
- end;
-
- {*********************}
- function MAIN(SUM, UPPER);
- begin
- i:=1;
- j:=i+5;
- k:=j-16;
- problem:=i+(j*k);
- writeln('I: ', i, ' J: ', j, ' K: ', k, ' Problem: ', problem);
- write('Enter upper ');
- upper:=read;
- sum:=addemup(1, upper); {sum of integers 1..upper}
- if isequal(sum, (upper*(upper+1))/2) then
- writeln('Sum = ', sum)
- else begin
- writeln('BUG: Sum = ', sum, '; should be ',
- (upper*(upper+1))/2);
- end;
- end;
-