







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








4/7/2005 1
4/7/2005 3
4/7/2005 4
4/7/2005 5
Specification of Programming
Languages
4/7/2005 6
4/7/2005 7
4/7/2005 8
4/7/2005 13
4/7/2005 14
4/7/2005 15
4/7/2005 16
4/7/2005 17
4/7/2005 18
4/7/2005 19
4/7/2005 20
4/7/2005 25
#include <stdio.h> int gcd(int u, int v) /* “functional” version / { if (v == 0) return u; else return gcd (v, u % v); / “tail” recursion / } main() / I/O driver */ { int x, y; printf("Input two integers:\n"); scanf("%d%d",&x,&y); printf("The gcd of %d and %d is %d\n", x,y,gcd(x,y)); return 0; } 4/7/2005 26
import java.io.; class IntWithGcd { public IntWithGcd( int val ) { value = val; } public int getValue() { return value; } public int gcd ( int v ) { int z = value; / “imperative” version */ int y = v; while ( y != 0 ) { int t = y; y = z % y; z = t; } return z; } private int value; }
4/7/2005 27
class GcdProg /* driver / { public static void main (String args[]) { System.out.println("Input two integers:"); BufferedReader in = new BufferedReader( new InputStreamReader(System.in)); try / must handle I/O exceptions / { IntWithGcd x = / create an object */ new IntWithGcd(Integer.parseInt(in.readLine())); int y = Integer.parseInt(in.readLine()); System.out.print("The gcd of " + x.getValue()
4/7/2005 28
4/7/2005 29
4/7/2005 30
4/7/2005 31
4/7/2005 32
4/7/2005 37
4/7/2005 38
4/7/2005 39
4/7/2005 40
4/7/2005 41
4/7/2005 42
4/7/2005 43
4/7/2005 44
4/7/2005 49
Some Functional Language
Concepts