/* * Reduces a fraction by dividing its numerator and denominator by their * greatest common divisor. */ void reduce_fraction(int *nump, /* input/output - */ int *denomp) /* numerator and denominator of fraction */ { int gcd; /* greatest common divisor of numerator & denominator */ gcd = find_gcd(*nump, *denomp); *nump = *nump / gcd; *denomp = *denomp / gcd; }
/* * Reduces a fraction by diving its numerator and denominator by their * greatest common divisor */ void reduce_fraction (int *nump, int *denomp) { int gcd; /* greatest common divisor of numerator & denominator */ gcd = find_gcd (*nump, *denomp); *nump = *nump / gcd; *denomp = *denomp / gcd; }
int main() { int a[60],i,n,gcd; scanf("%d",&n); printf("enter the element of array"); for(i=0;i<n;i++) scanf("%d",&a[i]); gcd=a[0]; for(i=1;i<n;i++) { gcd = find_gcd(gcd, a[i]); } printf("gcd=%d", gcd); return 0; }
int main() { mpz_t a , b , gcd; mpz_inits(a , b , gcd , NULL); printf("Enter first number : "); mpz_inp_str (a , stdin , 10 ); printf("\nEnter second number : "); mpz_inp_str (b , stdin , 10 ); find_gcd(gcd , a , b); printf("\nGCD of the given two numbers is : "); mpz_out_str (stdout , 10 , gcd); printf("\n"); }
int find_gcd(int a, int b) { if(b==0) return a; else return find_gcd(b, a%b); }