/* Program: stdgcd.c. */
/* Francis O'Donovan 5/12/97 */
#include <stdio.h>
main()
{
long
num1, num2, gcd, temp;
int
i;
printf( "Program: stdgcd.c.\n\n" );
printf(
"Calculates the gcd of two numbers.\n\n" );
printf(
"Francis O'Donovan 5/12/97\n\n\n" );
printf( "Please type in the two integers, pressing return
after each one.\n" );
scanf(
"%ld", &num1 );
scanf(
"%ld", &num2 );
if
( num1 > num2 )
{
temp = num2;
num2 = num1;
num1 = temp;
}
gcd = num1;
i =
0;
while ( ((num2%gcd) != 0) && ((num1%gcd) != 0) ) /* While
the remainder is not zero */
{
gcd--;
printf ( "While loop no. %d.\n", ++i) ;
}
printf( "The gcd of %ld and %ld is %ld.\n\n", num1,
num2, gcd );
}
© Francis O'Donovan
1999.