pages

Sunday, 11 April 2021

c-program to find the GCD of two numbers by recursion | c-programming languages

 program two find the GCD of the two number using recursion  in c-programming 




In this program, we will now calculate the GCD(greatest common divisor) of two number using recursion   in c-programming and takes two  positive number  from the user 






#include<stdio.h>
#include<conio.h>
int hcf(int n1,int n2);
void main()
{
   int n1,n2;
   printf("enter the two numbers\n");
   scanf("%d %d",&n1,&n2);
   printf("G.C.D of %d and %d is %d",n1,n2,hcf(n1,n2));
   getch();
}
int hcf(int n1,int n2)
{
    if(n2!=0)
         return hcf(n2,n1%n2);
    else
         return n1;
}































  output:-

               enter the number n1=12 and n2=16

                        GCD is 4 





For more c-programing examples:-


. fibonacci series using recursion in c-programming

 


c-program to find the sum of the natural number by recursion


.

c-program to calculate the factorial of the number by recursion


.

c-program to sum of the digits of the number in recursion


.




No comments:

Post a Comment