当前位置:网站首页>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
- Statistics, 8th Edition, Jia Junping, Chapter VIII, summary of knowledge points of hypothesis test and answers to exercises after class
- 使用 flask_whooshalchemyplus jieba实现flask的全局搜索
- Mathematical modeling idea of 2022 central China Cup
- Intel oneapi - opening a new era of heterogeneity
- msf生成payload大全
- Applet Web Capture -fiddler
- Lintcode logo queries the two nearest saplings
- How to understand the difference between technical thinking and business thinking in Bi?
- 【指针】数组逆序重新存放后并输出
猜你喜欢
Applet Web Capture -fiddler
Hackmyvm target series (1) -webmaster
Based on authorized access, cross host, and permission allocation under sqlserver
Web vulnerability - File Inclusion Vulnerability of file operation
Record an edu, SQL injection practice
《统计学》第八版贾俊平第十四章指数知识点总结及课后习题答案
captcha-killer验证码识别插件
Hcip -- MPLS experiment
SystemVerilog discusses loop loop structure and built-in loop variable I
Internet Management (Information Collection)
随机推荐
内网渗透之内网信息收集(五)
ES全文索引
MSF generate payload Encyclopedia
指针 --按字符串相反次序输出其中的所有字符
Apache APIs IX has the risk of rewriting the x-real-ip header (cve-2022-24112)
Sentinel overall workflow
浅谈漏洞发现思路
链队实现(C语言)
Detailed explanation of three ways of HTTP caching
Data mining - a discussion on sample imbalance in classification problems
Detailed explanation of network foundation routing
《统计学》第八版贾俊平第十章方差分析知识点总结及课后习题答案
函数:字符串反序存放
Low income from doing we media? 90% of people make mistakes in these three points
List and data frame of R language experiment III
Library management system
函数:求1-1/2+1/3-1/4+1/5-1/6+1/7-…+1/n
【指针】求二维数组中最大元素的值
Feature extraction and detection 14 plane object recognition
内网渗透之内网信息收集(二)