最大公约数c++

    #include <iostream>  
    using namespace std;  
      
    int gcd(int a,int b)  
    {  
        int t;  
        if(a<b)  
        {  
            t=a;  
            a=b;  
            b=t;  
        }  
        while(t=a%b)  
        {  
            a=b;  
            b=t;  
        }  
        return b;  
    }  
    int main()  
    {  
        int a,b;  
        while(cin>>a>>b)  
        {  
            cout<<gcd(a,b)<<endl;  
        }  
      
        return 0;  
    }  


猜你喜欢

转载自blog.csdn.net/qq_38534627/article/details/79691579