C language Function call 07-4 numbers of greatest common divisor and least common multiple

Source: Internet
Author: User
Tags greatest common divisor

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.