zoukankan      html  css  js  c++  java
  • c语言 8-8 求最大公约数

    1、

    #include <stdio.h>
    
    int gcd(int x, int y)
    {
        int max, min, tmp;
        if(x != y)
        {
        max = x > y ? x : y;
        min = x > y ? y : x;
        tmp = max % min;
        if(tmp != 0)
            gcd(min, tmp);
        else
            return min;
        }
    }
    
    int main(void)
    {
        int a, b;
        puts("please input two integers.");
        printf("a = "); scanf("%d", &a);
        printf("b = "); scanf("%d", &b);
        
        printf("result: %d
    ", gcd(a, b));
        return 0;
    }

    2、

    #include <stdio.h>
    
    int gcd(int x, int y)
    {
        int max, min, tmp;
        max = x > y ? x : y;
        min = x > y ? y : x;
        tmp = max % min;
        if(tmp != 0)
            gcd(min, tmp);
        else
            return min;    
    } 
    
    int main(void)
    {
        int a, b;
        puts("please input two integers.");
        printf("a = "); scanf("%d", &a);
        printf("b = "); scanf("%d", &b);
        
        printf("result: %d
    ", gcd(a, b));
        
        return 0;
    }

    3、

    #include <stdio.h>
    
    int gcd(int x, int y)
    {
        int max, min, tmp;
        max = x > y ? x : y;
        min = x > y ? y : x;
        tmp = max % min;
        if(tmp != 0)
            gcd(min, tmp);
        else
            return min;
    }
    
    int main(void)
    {
        int a, b;
        puts("please input two integers.");
        do
        {
            printf("a = "); scanf("%d", &a);
            if(a <= 0)
                puts("the range of a is: > 0.");
        }
        while(a <= 0);
        
        do
        {
            printf("b = "); scanf("%d", &b);
            if(b <= 0)
                puts("the rage of b is: > 0");
        }
        while(b <= 0);
        
        printf("the result:  %d
    ", gcd(a, b));
        
        return 0 ;
    }

  • 相关阅读:
    查看object信息
    Google C++单元测试框架之宏
    Google C++单元测试框架
    通过iscsi协议使用ceph rbd
    OpenStack+Ceph存储空间回收《转》
    IO
    golang之interface
    mysql 初始化
    ceph之ceph osd tree下的weight, reweight
    c++单元测试框架googletest
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14800203.html
Copyright © 2011-2022 走看看