GCD function for C

前端 未结 4 1849
礼貌的吻别
礼貌的吻别 2021-02-15 18:04

Q 1. Problem 5 (evenly divisible) I tried the brute force method but it took time, so I referred few sites and found this code:

#include
int gcd(i         


        
4条回答
  •  迷失自我
    2021-02-15 18:27

    This problem can also be solved in a very clean way with recursion:

    int gcd(int a, int b) {
        int remainder = a % b;
    
        if (remainder == 0) {
            return b;
        }
    
        return gcd(b, remainder);
    }
    

提交回复
热议问题