#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int gcd(int x, int y){
if(x < y)
return gcd(y, x);
if( y == 0)
return x;
else
{
if( x % 2 == 0)
{
if( y % 2 == 0)
return (gcd(x>>1, y>>1) << 1);
else
return gcd(x>>1, y);
}
else
{
if( y % 2 == 0)
return gcd(x, y>>1);
else
return gcd(x-y,y);
}
}
}
void main(){
int i = 0;
int x, y;
srand(time(NULL));
for(i = 0; i< 30; i++)
{
x = rand()%100;
y = rand()%100;
printf("x= %d, y = %d, gcd = %d\n", x,y,gcd(x,y));
}
getchar();
}
#include <stdlib.h>
#include <time.h>
int gcd(int x, int y){
if(x < y)
return gcd(y, x);
if( y == 0)
return x;
else
{
if( x % 2 == 0)
{
if( y % 2 == 0)
return (gcd(x>>1, y>>1) << 1);
else
return gcd(x>>1, y);
}
else
{
if( y % 2 == 0)
return gcd(x, y>>1);
else
return gcd(x-y,y);
}
}
}
void main(){
int i = 0;
int x, y;
srand(time(NULL));
for(i = 0; i< 30; i++)
{
x = rand()%100;
y = rand()%100;
printf("x= %d, y = %d, gcd = %d\n", x,y,gcd(x,y));
}
getchar();
}