C Programming
Computer Programming

C Program using function to Find G.C.D using recursion



Write a Program in C using function to Find G.C.D using recursion

\* C Program using function to Find G.C.D using recursion *\

# include < stdio.h >
# include < conio.h >
int   hcf(int n1, int n2) ;

int   main( )
{

int n1, n2 ;
printf("\n Enter the first positive integers: ") ;
scanf("%d", &n1) ;
printf(" Enter the second positive integers: ") ;
scanf("%d", &n2) ;
printf(" G.C.D of %d and %d is %d.", n1, n2, hcf(n1, n2)) ;
return 0 ;

}

int   hcf(int n1, int n2)
{

if ( n2 != 0 )
      return hcf( n2, n1%n2 ) ;
else
      return n1 ;

}

Output of Program :

Output of C Program using function to Find G.C.D using recursion