Find GCD using recursion | C program

Write a C Program to find GCD of two user given number using recursion , C program :

Code:


#include<stdio.h>
void main()
{
    int gcd(int ,int);
    int n,b,a;
    printf("Enter two  number:\n");
    scanf("%d%d",&a,&b);
    n=gcd(a,b);
    printf("%d",n);
}
int gcd(int a,int b)
{
    if(a==b)
        return a;
    else if(a%b==0)
        return b;
    else if(b%a==0)
        return a;
    else if(a>b)
        return(gcd(a%b,b));
    else
        return(gcd(a,b%a));
}

Output: 

Comments

Popular posts from this blog

TOP 10 PROGRAMMING LANGAUAGES COMMING 2021 | ARTICLE

Write a C-program to swap two number:

Print Fibonacci Series using Recursion | C program :