home *** CD-ROM | disk | FTP | other *** search
/ The Education Master 1994 (4th Edition) / EDUCATIONS_MASTER_4TH_EDITION.bin / files / progscal / tinypasc / turun.txt < prev    next >
Encoding:
Text File  |  1986-02-19  |  1.3 KB  |  54 lines

  1.   {TURUN -- A sample program written in Tiny Pascal }
  2.   var I, J, K, PROBLEM;
  3.   
  4.   {*********************}
  5.   function ISLESS(N1, N2);
  6.   begin  {returns 1 if n1<n2, 0 otherwise}
  7.     if n2-n1 then isless:=1   {truth value test is >0}
  8.     else isless:=0;
  9.     end;
  10.     
  11.   function ADDEMUP(LOWER, UPPER, SUM);
  12.   begin end;    {makes it a forward declaration}
  13.   
  14.   {*********************}
  15.   function ISEQUAL(N1, N2);
  16.   begin
  17.     if n2-n1 then isequal:=0   {false}
  18.     else
  19.     if n1-n2 then isequal:=0
  20.     else isequal:=1;
  21.     end;
  22.     
  23.   {***********************}
  24.   function ADDEMUP(LOWER, UPPER, SUM);
  25.         {SUM is a local}
  26.   begin
  27.     sum:=0;
  28.     while isless(lower, upper) do begin
  29.       sum:=sum+lower;
  30.       lower:=lower+1;
  31.       end;
  32.     addemup:=sum+lower;  { the last one was left out }
  33.     end;
  34.  
  35.   {*********************}
  36.   function MAIN(SUM, UPPER);
  37.   begin
  38.     i:=1;
  39.     j:=i+5;
  40.     k:=j-16;
  41.     problem:=i+(j*k);
  42.     writeln('I: ', i, ' J: ', j, ' K: ', k, ' Problem: ', problem);
  43.     write('Enter upper ');
  44.     upper:=read;
  45.     sum:=addemup(1, upper);  {sum of integers 1..upper}
  46.     if isequal(sum, (upper*(upper+1))/2) then
  47.       writeln('Sum = ', sum)
  48.     else begin
  49.       writeln('BUG: Sum = ', sum, '; should be ',
  50.                  (upper*(upper+1))/2);
  51.       end;
  52.     end;
  53.  
  54.