当前位置:网站首页>Function: find the maximum common divisor and the minimum common multiple of two positive numbers
Function: find the maximum common divisor and the minimum common multiple of two positive numbers
2022-07-06 14:35:00 【|Light|】
requirement
Write two functions , Find the greatest common divisor and the least common multiple of two positive numbers respectively , Call these two functions with the main function and output the result . Two positive numbers are entered by keyboard .
Code
/* * This function is used to calculate the maximum common divisor of two numbers */
int greatest_common_divisor(int m,int n)
{
int gcd=1,i;
for(i=0;i<10;i++)
{
if(m%2==0 && n%2==0)
{
gcd = gcd*2;
m=m/2;
n=n/2;
}
else if(m%3==0 && n%3==0)
{
gcd = gcd*3;
m=m/3;
n=n/3;
}
else if(m%5==0 && n%5==0)
{
gcd = gcd*5;
m=m/5;
n=n/5;
}
else if(m%7==0 && n%7==0)
{
gcd = gcd*7;
m=m/7;
n=n/7;
}
else
i=10;
}
return gcd;
}
/* * This function is used to calculate the least common multiple of two numbers */
int least_common_multiple(int m,int n)
{
int lcm=0;
lcm = m*n/greatest_common_divisor(m,n);
return lcm;
}
test
Test input
12 4
Output
The greatest common divisor of two numbers is :4, The least common multiple is :12
边栏推荐
- XSS unexpected event
- Statistics 8th Edition Jia Junping Chapter IX summary of knowledge points of classified data analysis and answers to exercises after class
- Tencent map circle
- 《统计学》第八版贾俊平第三章课后习题及答案总结
- Based on authorized access, cross host, and permission allocation under sqlserver
- XSS (cross site scripting attack) for security interview
- Wei Shen of Peking University revealed the current situation: his class is not very good, and there are only 5 or 6 middle-term students left after leaving class
- 5分钟掌握机器学习鸢尾花逻辑回归分类
- Mysql的事务是什么?什么是脏读,什么是幻读?不可重复读?
- Lintcode logo queries the two nearest saplings
猜你喜欢
Binary search tree concept
ES全文索引
“Hello IC World”
Wei Shen of Peking University revealed the current situation: his class is not very good, and there are only 5 or 6 middle-term students left after leaving class
Sqqyw (indifferent dot icon system) vulnerability recurrence and 74cms vulnerability recurrence
Harmonyos application development -- address book management system telmanagesys based on listcontainer [phonebook][api v6]
Constants, variables, and operators of SystemVerilog usage
Xray and burp linkage mining
循环队列(C语言)
How to understand the difference between technical thinking and business thinking in Bi?
随机推荐
函数:用牛顿迭代法求方程的根
How to earn the first pot of gold in CSDN (we are all creators)
Intranet information collection of Intranet penetration (2)
Statistics 8th Edition Jia Junping Chapter IX summary of knowledge points of classified data analysis and answers to exercises after class
flask实现强制登陆
MSF generate payload Encyclopedia
【指针】求二维数组中最大元素的值
The most popular colloquial system explains the base of numbers
关于交换a和b的值的四种方法
关于超星脚本出现乱码问题
Detailed explanation of network foundation routing
List and data frame of R language experiment III
DVWA (5th week)
Intranet information collection of Intranet penetration (3)
SystemVerilog discusses loop loop structure and built-in loop variable I
WEB漏洞-文件操作之文件包含漏洞
Applet Web Capture -fiddler
This article explains in detail how mockmvc is used in practical work
Statistics 8th Edition Jia Junping Chapter 12 summary of knowledge points of multiple linear regression and answers to exercises after class
《统计学》第八版贾俊平第二章课后习题及答案总结