







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!








3/31/2005 1
3/31/2005 2
3/31/2005 3
3/31/2005 4
3/31/2005 5
3/31/2005 6
3/31/2005 7
3/31/2005 8
3/31/2005 13
3/31/2005 14
3/31/2005 15
3/31/2005 17
3/31/2005 18
3/31/2005 19
3/31/2005 20
3/31/2005 25
3/31/2005 26
3/31/2005 27
3/31/2005 28
3/31/2005 29
3/31/2005 30
3/31/2005 31
3/31/2005 32
3/31/2005 37
.data A: .long 0 B: .long 0 sum: .long 0 .text main: jsr read movl d0,d movl d1,A jsr read movl d0,d movl d1,B movl A,d
movl B,d addl d1,d movl d1,sum movl sum,d movl d1,d jsr write movl sum,d movl #2,d divsl d1,d movl d1,d jsr write
3/31/2005 38
3/31/2005 39
3/31/2005 40
3/31/2005 41
3/31/2005 42
#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; }
3/31/2005 43
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; }
3/31/2005 44
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()
3/31/2005 49