C program to check the coprime of two number

Share

According to the theory of numbers, two integers, a and b, are considered to be coprime, comparatively prime, or mutually prime if there is only one positive integer that is a divisor of both of them, and that integer is 1.

#include <stdio.h>

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

int main() {
    int a, b;
    for(int i=0;i<2;i++){
    printf("Enter two numbers: ");
    scanf("%d %d", &a, &b);
    if (gcd(a, b) == 1) {
        printf("%d and %d are coprime.\n", a, b);
    } else {
        printf("%d and %d are not coprime.\n", a, b);
    }
}
    return 0;
}

Output

Explore further C programs here.

Share