#include#include 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); } }
Enter two numbers for GCD:5 15 Greatest common divisor of 5 and 15 is:5
Comments
Post a Comment