/*Program: euciter.c.*/
/*Iterative version of Euclidian algorithm.*/
/*Francis O'Donovan. 12-12-97.*/
#include <stdio.h>
main()
{
long
int x, y, temp;
int
i;
/*Intro*/
printf( "Program: euciter.c.\n\n" );
printf(
"Iterative version of Euclidian algorithm.\n\n" );
printf(
"Francis O'Donovan. 12-12-97.\n\n\n");
/* Read in numbers, and swap if x < y */
printf( "Please type in two numbers, and press return after
each.\n" );
scanf(
"%ld", &x );
scanf(
"%ld", &y );
if( x < y )
{
temp = x;
x = y;
y = temp;
}
/* Get gcd */
i =
0; /* initialise counter */
while ( y != 0 )
{
printf( "x = %ld, y = %ld.\n", x, y );
temp = y;
y = x%y;
x = temp;
printf( "While loop no. %d\n", ++i );
}
printf( "The GCD is %ld.\n\n", x );
}
© Francis O'Donovan
1999.