题解 | #最大公约数1#

最大公约数1

https://www.nowcoder.com/practice/021010dda9f04900a86738931a5600a4

#include <bits/stdc++.h>
using namespace std;
int GCD(int a, int b) {
    if (b == 0)return a;
    else return GCD(b, a % b);
}
int main() {
    int n;
    while (cin >> n) {
        int maxNum = INT_MIN;
        int minNum = INT_MAX;
        while (n--) {
            int temp;
            cin >> temp;
            if (temp > maxNum)maxNum = temp;
            if (temp < minNum)minNum = temp;
        }
        //求最大公约数
        cout << minNum << " " << maxNum << " " << GCD(minNum, maxNum) << endl;
    }

}
// 64 位输出请用 printf("%lld")

GCD

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务