当前位置:网站首页>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 (cross site scripting attack) for security interview
- 【指针】数组逆序重新存放后并输出
- Wu Enda's latest interview! Data centric reasons
- 内网渗透之内网信息收集(二)
- 数据库多表链接的查询方式
- SQL injection
- Statistics, 8th Edition, Jia Junping, Chapter 11 summary of knowledge points of univariate linear regression and answers to exercises after class
- Network layer - simple ARP disconnection
- JDBC事务、批处理以及连接池(超详细)
- Hackmyvm target series (1) -webmaster
猜你喜欢

四元数---基本概念(转载)

5分钟掌握机器学习鸢尾花逻辑回归分类

Low income from doing we media? 90% of people make mistakes in these three points

Hackmyvm target series (2) -warrior

captcha-killer验证码识别插件

Windows platform mongodb database installation

内网渗透之内网信息收集(三)

线程的实现方式总结

Intranet information collection of Intranet penetration (3)

《统计学》第八版贾俊平第八章假设检验知识点总结及课后习题答案
随机推荐
Proceedingjoinpoint API use
JVM memory model concept
指针--剔除字符串中的所有数字
How to understand the difference between technical thinking and business thinking in Bi?
浙大版《C语言程序设计实验与习题指导(第3版)》题目集
c语言学习总结(上)(更新中)
攻防世界MISC练习区(SimpleRAR、base64stego、功夫再高也怕菜刀)
Feature extraction and detection 14 plane object recognition
Based on authorized access, cross host, and permission allocation under sqlserver
Windows platform mongodb database installation
Markdown font color editing teaching
XSS unexpected event
《统计学》第八版贾俊平第八章假设检验知识点总结及课后习题答案
《统计学》第八版贾俊平第十一章一元线性回归知识点总结及课后习题答案
《统计学》第八版贾俊平第一章课后习题及答案总结
循环队列(C语言)
MSF generate payload Encyclopedia
Always of SystemVerilog usage_ comb 、always_ iff
XSS之冷门事件
New version of postman flows [introductory teaching chapter 01 send request]