The C language calculates the maximum and least common multiples of two numbers.

Source: Internet
Author: User

The C language calculates the maximum and least common multiples of two numbers.

// Author: kailuga-blog ParkHttp://www.cnblogs.com/kailugaji/


1 # include <stdio. h> 
2 // maximum common approx. 
3 int gys (int x, int y) {
4 int r; 
5 while (y! = 0) {
6 r = x % y; 
7 x = y; 
8 y = r; 
9} 
10 return x; 
11} 
12 // minimum public multiple 
13 int gbs (int x, int y) {
14 int z; 
15 z = x * y/gys (x, y); 
16 return z; 
17} 
18 
19 void main () {
20 int x, y; 
21 printf ("Please input two numbers: \ n"); 
22 scanf ("% d ", & x, & y); 
23 if (x <y) {// exchange x, y
24 x = x + y; 
25 y = x-y; 
26 x = x-y; 
27} 
28 printf ("% d and % d have the largest common approx. % d \ n", x, y, gys (x, y )); 
29 printf ("The minimum public multiples of % d and % d are % d \ n", x, y, gbs (x, y); 
30}



 


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.