当前位置:网站首页>Chapter 2: find the classical solution of the maximum Convention and the least common multiple of a and B, find the conventional solution of the maximum Convention and the least common multiple of a a
Chapter 2: find the classical solution of the maximum Convention and the least common multiple of a and B, find the conventional solution of the maximum Convention and the least common multiple of a a
2022-07-03 19:21:00 【Shares_ four】
// seek a,b Classical solution of maximum Convention and least common multiple of
int main()
{
long a, b, c, r, a1, b1;
printf(" Please enter a positive integer a,b: ");
scanf("%ld,%ld", &a, &b);
if (a < b)
{
c = a;
a = b;
b = c;
}
a1 = a;
b1 = b;
r = a % b;
while (r != 0) // The implementation of “ division algorithm
{
a = b;
b = r;
r = a % b;
}
printf("(%ld,%ld) = %ld\n", a1, b1, b);
printf("{%ld,%ld} = %ld\n", a1, b1, a1 * b1 / b);
return 0;
}
result :
// seek a,b The conventional solution of the maximum Convention and the least common multiple of
int main()
{
long a, b, c;
printf(" Please enter a positive integer a,b: ");
scanf("%ld,%ld", &a, &b);
if (a < b)
{
c = a;
a = b;
b = c;
}
for (c = b; c >= 1; c--)
if (a % c == 0 && b % c == 0) break; //C Is the trial quotient factor
printf("(%ld,%ld) = %ld\n", a, b, c);
printf("{%ld,%ld} = %ld\n", a, b, a * b / c);
return 0;
}
result :
// seek n The maximum Convention and the least common multiple of positive integers
int main()
{
int k, n;
long a, b, c, m[100];
printf(" Please enter the number of positive integers n: ");
scanf("%d", &n);
printf(" Please input... In turn %d A positive integer :", n);
for (k = 0; k <= n - 1; k++)
{
printf("\n Please enter the first %d A positive integer :", k + 1);
scanf(" %ld", &m[k]); // Input raw data
}
b = m[0];
for (k = 1; k <= n - 1; k++) // Cycle calculation n - 1 Time
{
a = m[k];
if (a < b)
{
c = a;
a = b; // In exchange for a、b, Make sure a>b
b = c;
}
for (c = b; c >= 1; c--)
if (a % c == 0 && b % c == 0) break; // Calculate the greatest common divisor
if (c == 1) break; // If the greatest common divisor is 1, Exit loop
b = c;
}
printf(" (%ld", m[0]); // Output the result of the greatest common divisor
for (k = 1; k <= n - 1; k++)
printf(", %ld", m[k]);
printf(") = %ld\n", c);
b = m[0];
for (k = 1; k <= n - 1; k++) // Cycle calculation n-1 Time
{
a = m[k];
if (a < b)
{
c = a;
a = b;
b = c;
}
for (c = a; c <= a * b; c = c + a)
if (c % b == 0) break;
b = c;
}
printf("{%ld", m[0]);
for (k = 1; k <= n - 1; k++)
printf(",%ld", m[k]);
printf("}=%ld\n", c);
return 0;
}
result :
边栏推荐
- 【Proteus仿真】用24C04与1602LCD设计的简易加密电子密码锁
- Valentine's Day - make an exclusive digital collection for your lover
- Bad mentality leads to different results
- SSM整合-前后台协议联调(列表功能、添加功能、添加功能状态处理、修改功能、删除功能)
- [water quality prediction] water quality prediction based on MATLAB Fuzzy Neural Network [including Matlab source code 1923]
- Verilog HDL continuous assignment statement, process assignment statement, process continuous assignment statement
- Record: MySQL changes the time zone
- Thinking about festivals
- 第一章:求奇因数代数和,求同吗小数和s(d, n),简化同码小数和s(d, n),拓广同码小数和s(d, n)
- TFs and SVN [closed] - TFs vs SVN [closed]
猜你喜欢
[mathematical modeling] ship three degree of freedom MMG model based on MATLAB [including Matlab source code 1925]
ActiveMQ的基础
During MySQL installation, the download interface is empty, and the components to be downloaded are not displayed. MySQL installer 8.0.28.0 download interface is empty solution
How to build an efficient information warehouse
Flutter网络和数据存储框架搭建 -b1
【水质预测】基于matlab模糊神经网络水质预测【含Matlab源码 1923期】
SQL injection for Web Security (1)
EGO Planner代码解析bspline_optimizer部分(2)
【LeetCode】【SQL】刷题笔记
2022.2.14 Li Kou - daily question - single element in an ordered array
随机推荐
Latex image rotates with title
[disease identification] machine vision lung cancer detection system based on Matlab GUI [including Matlab source code 1922]
Web Security (VIII) what is CSRF attack? Why can token prevent csdf attacks?
FBI警告:有人利用AI换脸冒充他人身份进行远程面试
Flutter网络和数据存储框架搭建 -b1
[new year job hopping season] test the technical summary of interviewers' favorite questions (with video tutorials and interview questions)
Recommend a GIF processing artifact less than 300K - gifsicle (free download)
Find the median of two positive arrays
Think of new ways
Differential constrained SPFA
math_泰勒公式
【疾病识别】基于matlab GUI机器视觉肺癌检测系统【含Matlab源码 1922期】
01 - QT OpenGL display OpenGL window
P3402 persistent and searchable
Counting from the East and counting from the West will stimulate 100 billion industries. Only storage manufacturers who dare to bite the "hard bone" will have more opportunities
Flume learning notes
How to build an efficient information warehouse
ActiveMQ的基础
Yolov3 network model building
第二十章:y= sin(x)/x,漫步坐标系计算,y= sin(x)/x 带廓幅图形,奥运五环,小球滚动与弹跳,流水显示,矩形优化裁剪,r个皇后全控nxn棋盘