当前位置:网站首页>(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; }
边栏推荐
- Basé sur... Netcore Development blog Project Starblog - (14) Implementation of theme switching function
- [untitled]
- What are the conditions for the opening of Tiktok live broadcast preview?
- Create real-time video chat in unity3d
- The boss said: whoever wants to use double to define the amount of goods, just pack up and go
- Save Private Ryan - map building + voltage dp+deque+ shortest circuit
- Hamburg University of Technology (tuhh) | intelligent problem solving as integrated hierarchical reinforcement learning
- [software implementation series] software implementation interview questions with SQL joint query diagram
- AI 助力藝術設計抄襲檢索新突破!劉芳教授團隊論文被多媒體頂級會議ACM MM錄用
- 在尋求人類智能AI的過程中,Meta將賭注押向了自監督學習
猜你喜欢
Remember another interview trip to Ali, which ends on three sides
A brief talk on professional modeler: the prospect and professional development of 3D game modeling industry in China
Write the first CUDA program
Buuctf QR code
AI 助力藝術設計抄襲檢索新突破!劉芳教授團隊論文被多媒體頂級會議ACM MM錄用
Www 2022 | taxoenrich: self supervised taxonomy complemented by Structural Semantics
Lichuang EDA learning notes 14: PCB board canvas settings
The reasons why QT fails to connect to the database and common solutions
Basic editing specifications and variables of shell script
String & memory function (detailed explanation)
随机推荐
長文綜述:大腦中的熵、自由能、對稱性和動力學
Yyds dry goods inventory it's not easy to say I love you | use the minimum web API to upload files
Buuctf QR code
15. System limitations and options
Format character%* s
On Valentine's day, I code a programmer's exclusive Bing Dwen Dwen (including the source code for free)
MySQL advanced SQL statement (1)
Winter vacation daily question -- a single element in an ordered array
Reading notes - learn to write: what is writing?
In yolov5, denselayer is used to replace focus, and the FPN structure is changed to bi FPN
Global and Chinese market of box seals 2022-2028: Research Report on technology, participants, trends, market size and share
求esp32C3板子連接mssql方法
Key knowledge of C language
Unity controls the selection of the previous and next characters
Network communication basic kit -- IPv4 socket structure
96% of the collected traffic is prevented by bubble mart of cloud hosting
Neo4j learning notes
[leetcode daily question] a single element in an ordered array
WP collection plug-in free WordPress collection hang up plug-in
Global and Chinese markets for electroencephalogram (EEG) devices 2022-2028: Research Report on technology, participants, trends, market size and share