Headlines
Loading...
C Program using function to find the GCD of 2 nos recursively

C Program using function to find the GCD of 2 nos recursively

Write a function to find the GCD of 2 nos recursively. Also write the main()
function to use it.

#include<stdio .h="">
#include<conio .h="">
int gcd(int a,int b);
void main()
 int r,g,a,b;
 clrscr();
 printf("Enter two numbers:");
 scanf("%d %d",&amp;a,&amp;b);
 g=gcd(a,b);
 printf("GCD : %d",g);
 getch();
 }
 int gcd (int a,int b)
 {
 if(b&gt;a)
 return gcd(b,a);
 if(b==0)
 return a;

 else
 return gcd(b,a%b);
 }

/* Output
Enter two numbers:2
4
GCD : 2
*/</conio></stdio>
*** PLEASE checkout the Best deals from for top sites like Amazon, Flipkart etc ***