Function call in C Language 03-maximum common divisor and minimum common multiple

Source: Internet
Author: User

Function call in C Language 03-maximum common divisor and minimum common multiple

// Function call/* ========================================== =============================== question: calculate the maximum common divisor and the least common multiple of two numbers. For example, the maximum common divisor of 16 and 12 is: 4 16 and 12 have the following least common multiples: 48 ============================================== ===================== */# include

 
  
Int GY (int m, int n) {int t, r; if (n> m) {t = m; m = n; n = t ;} while (r = m % n )! = 0) {m = n; n = r;} return (n);} int GB (int m, int n) {int k; k = m * n/GY (m, n); return (k);} main () {int x, y, gys, gbs; printf (enter two numbers :); scanf (% d, & x, & y); gys = GY (x, y); gbs = GB (x, y ); printf (the maximum common divisor of % d and % d is: % d, x, y, gys); printf (the minimum common multiples of % d and % d are: % d, x, y, gbs );} /* ===================================================== ============================= rating: write two independent functions GB-calculate the least common multiple and GY-calculate the maximum common number, so that the program is very compact and well maintained and checked. ========================================================== ========================

 


 

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.