当前位置:网站首页>[C language] summary of methods for solving the greatest common divisor
[C language] summary of methods for solving the greatest common divisor
2022-07-28 20:03:00 【An ran_】
Catalog
Method 1 : Circulation
#include <stdio.h>
int main()
{
int m=30,n=20;
while(n!=0)
{
int tmp=m%n;
m=n;
n=tmp;
}
printf("%d",m);
return 0;
}
Method 2 : Recursive method 【if-else sentence 】
#include <stdio.h>
int gcd(int a,int b);
int main()
{
int m=30,n=20;
int ret=gcd(m,n);
printf("%d",ret);
return 0;
}
int gcd(int a,int b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
Method 3 : Recursive simplified version 【 Ternary operator 】
#include <stdio.h>
#include <stdio.h>
int gcd(int a,int b);
int main()
{
int m=30,n=20;
int ret=gcd(m,n);
printf("%d",ret);
return 0;
}
int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
I don't remember , This is the first time to see Euclid / The principle of rolling division . Always read and understand , The problem is worked out , No review , Do it again, forget it, and look at the solution . Have no words for yourself .
I mean , No longer long heart , Here comes the fairy , I can't stop you from repeating the mistakes .

Today happens to be an opportunity 【 Both jobs only involve the solution of the greatest common divisor , The most basic , Can't write 】 Help me recognize some problems in my study now .
Now make the following adjustments : Monthly 30/31 Carry out phased summary and review . The way : Basic principles of dictation , And express your ideas in code .
Current pit :① rounding
② greatest common divisor
边栏推荐
- Digital filter design matlab
- String中常用的API
- KPMG China: insights into information technology audit projects of securities fund management institutions
- JS preventdefault() keyboard input limit onmousewheel stoppropagation stop event propagation
- Return and job management of saltstack
- Theoretical knowledge of digital image (I) (personal analysis)
- Hebei: stabilizing grain and expanding beans to help grain and oil production improve quality and efficiency
- Leetcode Day1 score ranking
- What is the process of swing event processing?
- Amazon launched Amazon one palm payment system, and the contactless palm vein recognition market is expected to explode
猜你喜欢

Know small and medium LAN WLAN

Concurrent programming, do you really understand?

Advanced notes (Part 2)

Use Hal Library of STM32 to drive 1.54 inch TFT screen (240*240 st7789v)

How to write the SQL statement of time to date?

一文读懂如何部署具有外部数据库的高可用 K3s

A chip company fell in round B

Digital filter design matlab

English translation Portuguese - batch English conversion Portuguese - free translation and conversion of various languages

What parameters should be passed in calling integer or character array functions
随机推荐
11. Learn MySQL union operator
Crawl IP
Left alignment function of Lua language (handwriting)
架构基本概念和架构本质
Stories of Party members | Li qingai uses cartoons to drive farmers to increase income and become rich
Hebei: stabilizing grain and expanding beans to help grain and oil production improve quality and efficiency
【经验之谈】关于维修电子设备的几点建议和经验
Edge detection and connection of image segmentation realized by MATLAB
Cloud computing notes part.1 - system management
BeanFactory not initialized or already closed - call ‘refresh‘ before accessing beans via the Applic
Android section 13 03xutils detailed explanation of database framework (addition, deletion and modification)
爬取IP
MySQL 8 creates master-slave replication based on Clone
[in depth study of 4g/5g/6g topics -44]: urllc-15 - in depth interpretation of 3GPP urllc related protocols, specifications and technical principles -9-low delay technology -3-non slot scheduling mini
What is the process of swing event processing?
JS batch add event listening onclick this event delegate target currenttarget onmouseenter OnMouseOver
Germany and Portugal have announced that they will not disable Huawei 5g equipment, but Germany will set strict restrictions!
Thoroughly understand bit operations - shift left, shift right
JS preventdefault() keyboard input limit onmousewheel stoppropagation stop event propagation
Function fitting based on MATLAB