当前位置:网站首页>C language is more than a variety of descriptions of size. Don't stick to one way of writing
C language is more than a variety of descriptions of size. Don't stick to one way of writing
2022-07-27 00:29:00 【TheshyO_ o】
Catalog
Preface
c Language entry code Multiple implementations than size
Just like all kinds of problems in life , There are always various ways to solve , The code is the same
One 、 Why try a variety of writing methods
It is conducive to the opening of early ideas , Accept and adapt to the world of code faster
It can also help you better understand the code written by others , When you see different code, you can understand it rather than repel it
Two 、 practice
1. The first way to write it
The code is as follows :
int main()// Than the size 1
{
int a = 0;
int b = 0;
scanf("%d %d", &a, &b);
if (a > b)
printf("%d\n", a);
else
printf("%d\n", b);
return 0;
}Directly in main To realize a and b The calculation of , And output a larger value
2. The second way
The code is as follows :
int max(int x, int y) // Than the size 2
{
if (x > y)
printf("%d\n", x);
else
printf("%d\n", y);
return 0;
}
int main()
{
int a = 0;
int b = 0;
scanf("%d %d", &a, &b);
int c = max(a, b);
return 0;
}Create a max, stay max At the same time, the ratio size and output , Take the whole thing outside to realize , Make the main code more concise
3. The third way
int max(int x,int y) // Than the size 3
{
if (x > y)
return x;
else
return y;
}
int main()
{
int a = 0;
int b = 0;
scanf("%d %d", &a, &b);
int c = max(a, b);
printf("%d\n", c);
return 0;
} stay max Middle computation , from main Medium output
summary
That's what we're going to talk about today , This article only briefly introduces c The most basic use of language , And various forms of code .
Of course , The ratio of size is not only written in these three forms , What do you want to tell you , Code is not static , You can achieve your goal in a variety of ways , Don't limit yourself to one form , Restrict sb.'s activities to a designated area or sphere .
I hope it can help you better understand the code written by others , And better write code .
边栏推荐
- Request attribute in crawler
- Matlab based medical imaging technology filtering backprojection simulation, including direct backprojection, S-L filtering, R-L filtering, LeWitt filtering
- C and pointer Chapter 18 runtime efficiency 18.3 runtime efficiency
- 【4.10 博弈论详解】
- 13_ Ensemble learning and random forests
- C and pointer Chapter 18 runtime environment 18.1 judgment of runtime environment
- Downloading and processing of sentinel-2
- Xshell连接服务器时报“Could not load host key”错误
- Reduced dimension mean dot product matrix multiplicative norm probability normal distribution square loss
- 【4.7 高斯消元详解】
猜你喜欢

Matlab simulation of image reconstruction using filtered back projection method

转置卷积相关

Deep learning of parameter adjustment skills

RESNET paper interpretation and code implementation (pytorch)

画冲击函数

知识蒸馏——pytorch实现

9_ Logistic regression

Web middleware log analysis script 1.0 (shell script)

Matlab based medical imaging technology filtering backprojection simulation, including direct backprojection, S-L filtering, R-L filtering, LeWitt filtering

12_决策树(Decision tree)
随机推荐
Web middleware log analysis script 2.0 (shell script)
Ubantu installing Oracle JDK
爬虫解析网页的find方法
C and pointers Chapter 18 runtime environment 18.4 summary
Find method of web page parsing by crawler
Shufflenet series (2): explanation of shufflenet V2 theory
Recbole use 1
TypeScript(tsconfig.json)
生成yolov5.wts文件出错
4. Talk about the famous Zhang Zhengyou calibration method
继承,继承,继承
9_ Logistic regression
Leetcode - linked list
AlexNet(Pytorch实现)
QML type system
[Qt]解决中文乱码问题
9_逻辑回归(Logistic Regression)
【AtCoder Beginner Contest 261 (A·B·C·D)】
AutoCAD的卸载后重新安装,删除注册表的详细过程
Comparative simulation of LEACH protocol performance, including the number of dead nodes, data transmission, network energy consumption, the number of cluster heads and load balance