gogoWebsite

The greatest common divisor (three numbers)

Updated to 2 days ago

topic: Find the greatest common divisor of three numbers.
analyze: There are many ways to find the greatest common divisor, common ones include prime factor decomposition, short division, round-rotating phase division, and more phase subtraction.
The text uses the method of dividing the phase. First, use two numbers to find their greatest common divisor, and then use this number and the third number to find their greatest common divisor.
You can search the algorithm steps for phase division by yourself.
Code Example

#include<>

int gcd(int x,int y){   
	int r;
    r=x%y;
    while(r!=0){
        x=y;
        y=r;
        r=x%y;
    }
    return (y);
}
main()
{
    int a,b,c,t;
    printf("Please enter three numbers:");
    scanf("%d%d%d",&a,&b,&c);
    t=gcd(a,b);
    t=gcd(t,c);
    printf("gcd=%d",t);
}