Function call
/*
==========================================================
Title: 4 numbers of greatest common divisor and least common multiple.
==========================================================
*/
#include <stdio.h>
Long Gys (long m,long N)
{
int t,r;
if (m<n)
{t=m;m=n;n=t;}
while ((r=m%n)!=0)
{
M=n;n=r;
}
return (n);
}
Long Gys (Long A,long b,long c)
{
Long q;
Q=gys (Gys (A, B), c);
return (q);
}
Long Gys (long A,long B, long C,long D)
{
Long q;
Q=gys (Gys (a,b,c), d);
return (q);
}
Long GBS (long A,long B)
{
Return A*b/gys (A, b);
}
Long GBS (Long A,long B,long c)
{
Return GBS (A, B) *c/gys (GBS (A, B), c);
}
Long GBS (long A,long b,long C,long D)
{
return GBS (A,B,C) *d/gys (GBS (A,B,C), d);
}
void Main ()
{
Long a,b,c,d;
Long Gyshu,gbshu;
printf ("Enter four numbers:");
scanf ("%ld%ld%ld%ld", &a,&b,&c,&d);
Gyshu=gys (A,B,C,D);
Gbshu=gbs (A,B,C,D);
printf ("%ld,%ld,%ld,%ld greatest common divisor:%ld\n", A,b,c,d,gyshu);
printf ("%ld,%ld,%ld,%ld least common multiple:%ld\n", A,b,c,d,gbshu);
}
/*
====================================================================
Evaluation:
The point is to repeat the call! Always calculate the result as a number, the realization of the first calculation of two number A, B,
Gys (A, B) or GBS (A, B) as a number with C re-call function "Gys" or "GBS", similarly,
Gys (A,B,C) or GBS (A,B,C) as a number with the recall function "Gys" or "GBS",
Even more number of conventions and common multiple can be achieved! If the numbers are larger and bigger, you need to
Change to double type!
Cons: Obviously this method is intuitive but slow to write programs! The reader can try to use a temp variable
Keep the latest number of conventions until the last one is completed. The problem is converted to always ask for two
Number of conventions.
=====================================================================
*/
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
C language Function call 07-4 numbers of greatest common divisor and least common multiple