Skip to content

Great Common Divisor

Author: Pasit Sangprachathanarak


View Problem Statement

Source: PROGRAMMING.IN.TH

Difficulty: Easy

Tags: Implementation

Prerequisites:

View External Solution

เฉลย

เฉลย
#include <stdio.h>

int main() {
    int a, b, gcd;
    scanf("%d %d", &a, &b);
    for (int i = 1; i <= a && i <= b; i++) {
        if (a % i == 0 && b % i == 0) {
            gcd = i;
        }
    }
    printf("%d", gcd);
}
#include <iostream>

using namespace std;

int main() {
    int a, b, gcd;
    cin >> a >> b;
    for (int i = 1; i <= a && i <= b; i++) {
        if (a % i == 0 && b % i == 0) {
            gcd = i;
        }
    }
    cout << gcd;
}