C Program to Find G.C.D Using Recursion - Source Code, Output & Execution Flow

C Program to Find G.C.D Using Recursion

This C program finds the greatest common divisor using Euclid's recursive algorithm.

#include <stdio.h>
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int main() {
    int a, b;
    printf("Enter two numbers: ");
    scanf("%d %d", &a, &b);
    printf("GCD = %d
", gcd(a, b));
    return 0;
}
Enter two numbers: 36 60
GCD = 12

In this program, the input is read first when required, the core logic is applied step by step, and the final result is displayed using printf(). Follow the execution flow beside the code to understand how each statement contributes to the output.

Sai Kishore Randhi, author
About the author

Sai Kishore Randhi

Embedded systems, VLSI, and chip design

Sai Kishore writes about embedded systems, VLSI, chip design, and the programming concepts behind modern hardware.

View LinkedIn profile ↗