数学问题——gcd\gcl

//非递归形式 
void gcl(int m,int n){
    int max,min,remainder;
    max = m > n ? m : n;
    min = m < n ? m : n;

    do{
        remainder = max % min ;
        max = min;
        min = remainder;        
    }while(remainder != 0) ;
    
    printf("%d",max);
}

//递归形式
int gcd(int a,int b){
    if(b == 0){
        return a;
    }else{
        return gcd(b,a % b);
    }
}

猜你喜欢

转载自www.cnblogs.com/juanzhi/p/12898685.html
今日推荐