当前位置:网站首页>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
边栏推荐
- Statistics 8th Edition Jia Junping Chapter 10 summary of knowledge points of analysis of variance and answers to exercises after class
- 《统计学》第八版贾俊平第十章方差分析知识点总结及课后习题答案
- XSS之冷门事件
- 安全面试之XSS(跨站脚本攻击)
- 内网渗透之内网信息收集(二)
- 链队实现(C语言)
- 5分钟掌握机器学习鸢尾花逻辑回归分类
- Attack and defense world misc practice area (GIF lift table ext3)
- 《统计学》第八版贾俊平第一章课后习题及答案总结
- Internet Management (Information Collection)
猜你喜欢
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)
Résumé des points de connaissance et des réponses aux exercices après la classe du chapitre 7 de Jia junping dans la huitième édition des statistiques
1.支付系统
Constants, variables, and operators of SystemVerilog usage
Data mining - a discussion on sample imbalance in classification problems
Detailed explanation of network foundation
Lintcode logo queries the two nearest saplings
《统计学》第八版贾俊平第十章方差分析知识点总结及课后习题答案
内网渗透之内网信息收集(四)
随机推荐
Build domain environment (win)
浅谈漏洞发现思路
《统计学》第八版贾俊平第十章方差分析知识点总结及课后习题答案
移植蜂鸟E203内核至达芬奇pro35T【集创芯来RISC-V杯】(一)
函数:求方程的根
Harmonyos application development -- address book management system telmanagesys based on listcontainer [phonebook][api v6]
MySQL interview questions (4)
flask实现强制登陆
Xray and burp linkage mining
《统计学》第八版贾俊平第二章课后习题及答案总结
Binary search tree concept
Internet Management (Information Collection)
Sentinel overall workflow
XSS unexpected event
Applet Web Capture -fiddler
C language file operation
servlet中 servlet context与 session与 request三个对象的常用方法和存放数据的作用域。
《英特尔 oneAPI—打开异构新纪元》
c语言学习总结(上)(更新中)
Overview of LNMP architecture and construction of related services