#include <stdio.h> int GCD (int x, int y) { int b; if((x%y) == 0) { b = y; } else if((y%x) == 0) { b = x; } else { GCD(y, x%y); } return b; } int get_input() { int a, i=0; scanf("%d\n", &a); if(a<=0) { for (i = 0; a <= 0; i++) { printf("Please enter an integer greater than 0\n"); scanf("%d\n", &a); } } return a; } int main() { int x, y, z; printf("This program computes the greatest common divisor\n"); printf("of positive integers x and y, entered by the user\n"); printf("Inputs must be integers greater than zero\n\n"); printf("Enter integer x:"); x = get_input(); printf("Enter integer y:"); y = get_input(); z = GCD(x,y); printf("The GCD of %d and %d is %d\n", x, y, z); return 0; }

----------------------------------------------OUTPUT-------------------------------------------------------------- with example numbers input highlighted. This is exactly how it appears on SSH(sunblast)

This program computes the greatest common divisor

of positive integers x and y, entered by the user

Inputs must be integers greater than zero

Enter integer x:6

4

Enter integer y:3

The GCD of 6 and 4 is 4

This post has been edited by **Dabucs78**: 17 February 2009 - 03:11 PM