C program to calculate GCD.

#include<stdio.h>
int Calculate_GCD(int x,int y);
int main()
{
    int a, b, gcd;
    printf("Enter two numbers:\n");
    scanf("%d%d",&a,&b);
    gcd=Calculate_GCD(a,b);
    printf("\nGCD of %d and %d is:%d",a,b,gcd);
    return 0;
}
int Calculate_GCD(int x,int y)
{
    if(x>y)
        Calculate_GCD(x-y,y);
    else if(y>x)
        Calculate_GCD(y,y-x);
    else
        return x;
}

*** Input && Output ***



Post a Comment

0 Comments