20_10

Write a program in C to find GCD of two numbers using recursion.

 Source code:

//Write a program in C to find GCD of two numbers using recursion.


#include<stdio.h>

int GCD_cal(int a,int b)

{

    while(a!=b)

    {

        if(a>b)

            return GCD_cal(a-b,b);

        else

            return GCD_cal(a,b-a);

    }

    return a;

}

int main()

{

int num1, num2, gcd;

printf("Enter the first number: ");

scanf("%d",&num1); /*Enter 1st number */

printf("Enter the second number: ");

scanf("%d",&num2); /*Enter 2nd number */


  gcd = GCD_cal(num1,num2);

  printf("The GCD of %d and %d is: %d\n",num1,num2,gcd);

  return 0;

}

Output:

program in C to find GCD of two numbers using recursion


No comments:

Post a Comment

Write a program in C to convert a decimal number to binary using recursion.

 Source code: //Write a program in C to convert a decimal number to binary using recursion. #include<stdio.h> long convertB_to_D(int d...