当前位置:网站首页>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(跨站脚本攻击)
- Record once, modify password logic vulnerability actual combat
- 网络基础详解
- New version of postman flows [introductory teaching chapter 01 send request]
- Sqqyw (indifferent dot icon system) vulnerability recurrence and 74cms vulnerability recurrence
- 指针:最大值、最小值和平均值
- “人生若只如初见”——RISC-V
猜你喜欢
《统计学》第八版贾俊平第三章课后习题及答案总结
《统计学》第八版贾俊平第八章假设检验知识点总结及课后习题答案
sqqyw(淡然点图标系统)漏洞复现和74cms漏洞复现
《统计学》第八版贾俊平第十四章指数知识点总结及课后习题答案
JDBC read this article is enough
Uibutton status exploration and customization
High concurrency programming series: 6 steps of JVM performance tuning and detailed explanation of key tuning parameters
Statistics 8th Edition Jia Junping Chapter 3 after class exercises and answer summary
内网渗透之内网信息收集(二)
网络基础详解
随机推荐
《统计学》第八版贾俊平第十四章指数知识点总结及课后习题答案
“Hello IC World”
Constants, variables, and operators of SystemVerilog usage
Proceedingjoinpoint API use
函数:求两个正数的最大公约数和最小公倍
MySQL interview questions (4)
指针--剔除字符串中的所有数字
网络基础之路由详解
msf生成payload大全
High concurrency programming series: 6 steps of JVM performance tuning and detailed explanation of key tuning parameters
浙大版《C语言程序设计实验与习题指导(第3版)》题目集
SQL injection
《统计学》第八版贾俊平第十一章一元线性回归知识点总结及课后习题答案
JDBC事务、批处理以及连接池(超详细)
《统计学》第八版贾俊平第三章课后习题及答案总结
Sqqyw (indifferent dot icon system) vulnerability recurrence and 74cms vulnerability recurrence
函数:求方程的根
指针:最大值、最小值和平均值
Attack and defense world misc practice area (GIF lift table ext3)
内网渗透之内网信息收集(三)