当前位置:网站首页>(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; }
边栏推荐
- The difference between lambda expressions and anonymous inner classes
- Chain ide -- the infrastructure of the metauniverse
- Summarize the past to motivate yourself to move on
- [Yugong series] February 2022 attack and defense world advanced question misc-83 (QR easy)
- The automatic control system of pump station has powerful functions and diverse application scenarios
- 17. File i/o buffer
- ZABBIX API batch delete a template of the host
- Pytoch residual network RESNET
- Reading notes - learn to write: what is writing?
- LV1 tire pressure monitoring
猜你喜欢

Fudan released its first review paper on the construction and application of multimodal knowledge atlas, comprehensively describing the existing mmkg technology system and progress

Yyds dry goods inventory it's not easy to say I love you | use the minimum web API to upload files

Introduction to graphics: graphic painting (I)

The first spring of the new year | a full set of property management application templates are presented, and Bi construction is "out of the box"

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

Idea if a class cannot be found, it will be red

Unspeakable Prometheus monitoring practice
![[software implementation series] software implementation interview questions with SQL joint query diagram](/img/8b/8718fea82f83a6169ea5d8c2e5b645.jpg)
[software implementation series] software implementation interview questions with SQL joint query diagram

Solve the problem that the tabbar navigation at the bottom of vantui does not correspond to the page (window.loading.hash)

C learning notes: C foundation - Language & characteristics interpretation
随机推荐
Introduction to graphics: graphic painting (I)
Libcblas appears when installing opencv import CV2 so. 3:cannot open shared object file:NO such file or directory
Sword finger offer 20 String representing numeric value
Global and Chinese market of small batteries 2022-2028: Research Report on technology, participants, trends, market size and share
Properties of binary trees (numerical aspects)
Servlet simple verification code generation
Global and Chinese market of cell scrapers 2022-2028: Research Report on technology, participants, trends, market size and share
Measurement fitting based on Halcon learning [4] measure_ arc. Hdev routine
60 year old people buy medical insurance and recommend a better product
There is no need to authorize the automatic dream weaving collection plug-in for dream weaving collection
Unspeakable Prometheus monitoring practice
Basé sur... Netcore Development blog Project Starblog - (14) Implementation of theme switching function
Record a problem that soft deletion fails due to warehouse level error
Basic editing specifications and variables of shell script
C # learning notes: structure of CS documents
Format character%* s
The difference between int (1) and int (10)
[untitled]
STM32 key content
Summarize the past to motivate yourself to move on