C Program for GCD

Ram Pothuraju
#include<stdio.h>
#include<conio.h>
int GCD(int,int);

void main()
{
 int n1,n2;
 clrscr();
 printf("\n Enter two numbers for GCD:");
 scanf("%d %d",&n1,&n2);

 printf("\n Greatest common divisor of %d and %d is:%d",n1,n2,GCD(n1,n2));
getch();
}
int GCD(int m,int n)
{
 if(n==0)
  return m;
 else
 {
  if(n>m)
  {
   n=n+m;
   m=n-m;
   n=n-m;
  }
  return GCD(n,m%n);
 }

}

</conio.h></stdio.h>

OUTPUT


Enter two numbers for GCD:5 15

Greatest common divisor of 5 and 15 is:5


Post a Comment

0Comments

Post a Comment (0)