C Program To Find GCD of Two Numbers using Recursion: Euclid’s Algorithm

If you are looking to know the concept about “C Program To Find GCD of Two Numbers using Recursion: Euclid’s Algorithm” then you are in the perfect tutorial. Shall we start the discussion to clarify it below? Come on! Let’s go.

C Program To Find GCD of Two Numbers using Recursion: Euclid’s Algorithm

C Program To Find GCD of Two Numbers using Recursion: Euclid’s Algorithm

Program Code

#include<stdio.h>  
  
int gcd(int, int);  
  
int main()  
{  
    int num1, num2;  
  
    printf("Enter 2 positive integer numbersn");  
    scanf("%d%d", &num1, &num2);  
  
    printf("nGCD of %d and %d is %d.n", num1, num2, gcd(num1, num2));  
  
    return 0;  
}  
  
int gcd(int n1, int n2)  
{  
    if(n1 == 0) return n2;  
    if(n2 == 0) return n1;  
  
    if(n1 > n2)  
        return gcd(n1%n2, n2);  
    else  
        return gcd(n1, n2%n1);  
}

I hope this article helps you to know the concept about “C Program To Find GCD of Two Numbers using Recursion: Euclid’s Algorithm“. If you face any issues please let me know via the comment section. Share this article with other C/C++ developers via social networks.

Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment