当前位置:网站首页>[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
边栏推荐
- Know small and medium LAN WLAN
- Sequential linear table - practice in class
- Can China make a breakthrough in the future development of the meta universe and occupy the highland?
- Labelme(一)
- 基于QTGUI图像界面的空战游戏设计
- A chip company fell in round B
- 基于MATLAB的函数拟合
- With the help of panel industry innovation, will FPGA become the best choice for TCON?
- JS batch add event listening onclick this event delegate target currenttarget onmouseenter OnMouseOver
- Data system of saltstack
猜你喜欢
Stories of Party members | Li qingai uses cartoons to drive farmers to increase income and become rich
Basic usage of docker
Implementation of strstr in C language
Integration and implementation of login click graphic verification code in personal blog system
数字滤波器设计——Matlab
This customized keyboard turns me on~
Oracle insert数据时字符串中有‘单引号问题
[wechat applet development] page navigation and parameter transmission
Handan, Hebei: expand grassroots employment space and help college graduates obtain employment
Source insight project import and use tutorial
随机推荐
Machine learning -- model evaluation, selection and verification
云原生编程挑战赛火热开赛,51 万奖金等你来挑战!
Business visualization - let your flowchart "run" (4. Actual business scenario test)
Leetcode day3 find duplicate email addresses
NetCoreAPI操作Excel表格
C language implementation of strncpy
冲刺金九银十丨熬夜半个月汇集大厂Android岗1600道面试真题
数字滤波器设计——Matlab
JS batch add event listening onclick this event delegate target currenttarget onmouseenter OnMouseOver
CodeIgnier框架实现restful API接口编程
一文读懂如何部署具有外部数据库的高可用 K3s
C language functions and pointers
MySQL8 基于clone创建主从复制
时间转日期的sql语句应该怎么写?
Use of strtok and strError
基于MATLAB的函数拟合
Oracle insert数据时字符串中有‘单引号问题
Advanced notes (Part 2)
Redis笔记
Redis notes