Function call in C Language 08-the brute-force law is used to calculate the maximum and minimum public multiples of the four numbers, and the 08 common

Source: Internet
Author: User

Function call in C Language 08-the brute-force law is used to calculate the maximum and minimum public multiples of the four numbers, and the 08 common
// Array Enumeration
/*
========================================================== ============================
Question: calculate the maximum or least common number of four numbers.
========================================================== ============================
*/
# Include <stdio. h>
# Define N 4
Main ()
{
Int a [N], gys, gbs;
Int I, j, m = 1;
Int flag = 1;
Printf ("Enter % d integers:", N );
For (I = 0; I <N; I ++)
Scanf ("% d", & a [I]);
For (j = a [0]; j> = 1; j --)
If (a [0] % j = 0 & a [1] % j = 0 & a [2] % j = 0 & a [3] % j = 0)
{
Gys = j;
Break;
}
Printf ("maximum common divisor: % d \ n", gys );
While (flag)
{
If (m % a [0] = 0 & m % a [1] = 0 & m % a [2] = 0 & m % a [3] = 0)
{
Gbs = m;
Flag = 0;
}
Else m ++;
}
Printf ("minimum public multiple: % d \ n", gbs );
}


/*
========================================================== ============================
Rating: it is a brute-force method. It is obviously not a good algorithm, but for computers with fast computing speed,
This is a practical approach.
========================================================== ============================
*/

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.