当前位置:网站首页>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 .
边栏推荐
猜你喜欢

知识蒸馏——pytorch实现

Go exceed API source code reading (IV) -- save (), SaveAs (name string)

Request attribute in crawler
![[PCB open source sharing] stc8a8k64d4 development board](/img/df/14f47295dace857c0a32545c3eca39.png)
[PCB open source sharing] stc8a8k64d4 development board

Viterbi Viterbi decoding bit error rate simulation, modulation is QPSK, channel is Gaussian white noise

12_决策树(Decision tree)

20220720折腾deeplabcut2

【AcWing第61场周赛】

放图仓库-Tsai

Shang school software testing (1) software testing curriculum system, advantages, learning suggestions, understanding software, software testing and defects, software testing process, debugging and te
随机推荐
torch.相关函数
ResNet论文解读及代码实现(pytorch)
Find method of web page parsing by crawler
C and pointers Chapter 18 runtime environment 18.4 summary
【AcWing第61场周赛】
机器学习模型——lightGBM
[Qt]属性
生成yolov5.wts文件出错
5_线性回归(Linear Regression)
10_评价分类结果(Evaluate classification)
JS, one of the methods of object merging Assign (), recursive assignment & method of array merging..., array. Concat (), array. Push. Apply (), array. Push ()
LeetCode题目——二叉树篇
Resolve Microsoft 365 and Visio conflicts
Drawing warehouse-3 (functional image)
AutoCAD的卸载后重新安装,删除注册表的详细过程
Configure deeplobcut2 with your head covered
c语言 static运用,灵活改变生命周期,让你写代码如鱼得水
Draw impact function
Leetcode topic - binary tree chapter
2022_ SummerBlog_ 008