当前位置:网站首页>(column 23) typical C language problem: find the minimum common multiple and maximum common divisor of two numbers. (two solutions)
(column 23) typical C language problem: find the minimum common multiple and maximum common divisor of two numbers. (two solutions)
2022-07-04 02:39:00 【boss. Peipei】
give the result as follows :

The first one is :
#include<stdio.h> int main() { int min(int a,int b); // Function find minimum int max(int c,int d); // Function to find the maximum int x,y,i,j=0,sum,num,v; printf(" Please enter two numbers :"); scanf("%d %d",&x,&y); for(i=2;i<=min(x,y);i++) { if(x%i==0&&y%i==0) // Whether there is a number divided by two numbers at the same time before the minimum value of two numbers { if(i>j) { j=i; // Find the greatest common divisor } } } sum=x*y; // The least common multiple is the product of two numbers for(v=max(x,y);v<=x*y;v++) { if(v%x==0&&v%y==0) // Find the number divisible { if(v<sum) { sum=v; // Find the least common multiple } } } printf(" greatest common divisor :%d",j); printf("\n"); printf(" Minimum common multiple :%d",sum); return 0; } int min(int a,int b) { return (a<b?a:b); } int max(int c,int d) { return (c>d?c:d); }
The second kind :
#include<stdio.h> int main() { int a,b,t,r,n; printf(" Please enter two numbers :\n"); scanf("%d %d",&a,&b); if(a<b) // Sort the two numbers from large to small { t=b; b=a; a=t; } r=a%b; // The least common divisor of two numbers n=a*b; // The greatest common multiple of two numbers while(r!=0) { a=b; b=r; r=a%b; } printf(" The greatest common divisor of these two numbers is %d, The minimum common multiple is %d\n",b,n/b); return 0; }
边栏推荐
- Sword finger offer 14- I. cut rope
- [Yugong series] February 2022 attack and defense world advanced question misc-83 (QR easy)
- Node solves cross domain problems
- Talking about custom conditions and handling errors in MySQL Foundation
- Pagoda SSL can't be accessed? 443 port occupied? resolvent
- Push technology practice | master these two tuning skills to speed up tidb performance a thousand times!
- Basé sur... Netcore Development blog Project Starblog - (14) Implementation of theme switching function
- The reasons why QT fails to connect to the database and common solutions
- Global and Chinese market of thin film deposition systems 2022-2028: Research Report on technology, participants, trends, market size and share
- false sharing
猜你喜欢

Final consistency of MESI cache in CPU -- why does CPU need cache

VRRP+BFD

Comment la transformation numérique du crédit d'information de la Chine passe - t - elle du ciel au bout des doigts?

C language black Technology: Archimedes spiral! Novel, interesting, advanced~

AI 助力藝術設計抄襲檢索新突破!劉芳教授團隊論文被多媒體頂級會議ACM MM錄用

Database concept and installation

JVM performance tuning and practical basic theory - medium

長文綜述:大腦中的熵、自由能、對稱性和動力學

Contest3145 - the 37th game of 2021 freshman individual training match_ 1: Origami
![[leetcode daily question] a single element in an ordered array](/img/3a/2b465589b70cd6aeec08e79fcf40d4.jpg)
[leetcode daily question] a single element in an ordered array
随机推荐
7 * 24-hour business without interruption! Practice of applying multiple live landing in rookie villages
Lichuang EDA learning notes 14: PCB board canvas settings
Libcblas appears when installing opencv import CV2 so. 3:cannot open shared object file:NO such file or directory
Contest3145 - the 37th game of 2021 freshman individual training match_ F: Smallest ball
15. System limitations and options
JVM performance tuning and practical basic theory - medium
Mysql-15 aggregate function
String: LV1 eat hot pot
I stepped on a foundation pit today
在尋求人類智能AI的過程中,Meta將賭注押向了自監督學習
13. Time conversion function
The "two-way link" of pushing messages helps app quickly realize two-way communication capability
Create real-time video chat in unity3d
Hamburg University of Technology (tuhh) | intelligent problem solving as integrated hierarchical reinforcement learning
Idea if a class cannot be found, it will be red
Global and Chinese markets of advanced X-ray inspection system (Axi) in PCB 2022-2028: Research Report on technology, participants, trends, market size and share
Basé sur... Netcore Development blog Project Starblog - (14) Implementation of theme switching function
I stepped on a foundation pit today
LV1 previous life archives
Unity knapsack system (code to center and exchange items)