Write a program to calculate G.C.D of any two numbers.
SOLUTION:
/* * Calculate G.C.D of any two numbers * Written by Shaeed Khan. * Date: 05 Aug 2014 * Version- 1.0 * Language: C */ #include < stdio.h > #include < stdlib.h > void main() { int n1,n2,x; printf("Enter two numbers:"); scanf("%d%d",&n1,&n2); x=gcd(n1,n2); printf("%d ",x); } int gcd(int n1,int n2) { while(n1!=n2) { if(n1>n2) n1=n1-n2; else n2=n2-n1; } return n1; }
No comments:
Post a Comment