// The basic I/O library available is built on three primitives, // get(int *ch), peek(int *ch), and put(int ch). Get and // peek both read from stdin. Peek leaves the character // unread. EOF returns -1. Put writes to stdout. Programs // must be invoked on Unix as "prog < infile > outfile". // They are not meant for interactive I/O and buffering // is undefined. // Note that get and peek *must* have signed ints as // parameters. Put may be given a char etc because it // will be type coerced automatically to the encompassing // int type. // On windows, character 13 is stripped on input, and // added on output after character 10 is put. procedure Mod (unsigned int M, N, unsigned int *result) begin *result = M - ((M/N) * N) end procedure writeu(unsigned int num) begin // write num with no leading spaces or zeroes. if (num > 10) writeu(num/10) endif Mod (num, 10, &num); put(num+'0'); end procedure printstring(char *s) begin int i; // print the string *literal* that is the parameter. i = 0 while (s[i] != 0) put(s[i]) i = i+1 endwhile end procedure newline() begin put(10) end procedure Gcd( unsigned int M, unsigned int N, unsigned int *result ) begin unsigned int Rem; while ( N > 0 ) Mod(M, N, &Rem); M = N; N = Rem; endwhile *result = M; end program begin unsigned int val; Gcd( 45, 35, &val ); printstring( "Gcd( 45, 35 ) = "); writeu(val); newline(); Gcd( 1989, 1590, &val ); printstring( "Gcd( 1989, 1590 ) = "); writeu(val); newline(); end