当前位置:网站首页>【C语言实现】求两个整数的较大值
【C语言实现】求两个整数的较大值
2022-08-01 21:34:00 【万羽西】
方法一
通过 if else 来判断大小,分别打印。
#include <stdio.h>
int main()
{
int x = 0;
int y = 0;
scanf("%d %d", &x, &y);
if (x > y)
{
printf("max = %d\n", x);
}
else
{
printf("max = %d\n", y);
}
return 0;
}
方法二
利用函数求出最大值
#include <stdio.h>
int Max(int x, int y)
{
if (x > y)
{
return x;
}
else
{
return y;
}
}
int main()
{
int x = 0;
int y = 0;
scanf("%d %d", &x, &y);
int max = Max(x, y);
printf("max = %d\n", max);
return 0;
}
方法三
利用三目操作符(条件操作符)比较
#include <stdio.h>
int main()
{
int x = 0;
int y = 0;
scanf("%d %d", &x, &y);
int max = x > y ? x : y;
printf("max = %d\n", max);
return 0;
}
总结
以上就是该题目三种解法,博主比较钟爱第三种,因为代码简洁,目的性也强,就是要理解三目操作符的用法即可,以后也会更新更多常见题目的解法,尽量做到一题多解,开阔思路,找到最优解,最后,喜欢的话,希望家人们给个一键三连多多支持,博主也多加努力!!
+
关注
+
收藏嗷!!
边栏推荐
- 空间数据库开源路,超图+openGauss风起禹贡
- C Expert Programming Chapter 1 C: Through the Fog of Time and Space 1.1 The Prehistoric Phase of the C Language
- PyQt5 + MySQL5.8 【学生信息管理系统】【增删改查】
- [@synthesize in Objective-C]
- 【Unity实战100例】文件压缩Zip和ZIP文件的解压
- 【Jmeter常用断言组件】
- 树莓派的信息显示小屏幕,显示时间、IP地址、CPU信息、内存信息(c语言),四线的i2c通信,0.96寸oled屏幕
- Spark practice questions + answers
- Small program -- subcontracting
- ARFoundation Getting Started Tutorial U2-AR Scene Screenshot Screenshot
猜你喜欢
ISC2022 HackingClub white hat summit countdown 1 day!Most comprehensive agenda formally announced!Yuan universe, wonderful!
方舟:生存进化官服和私服区别
[Chinese tree tags - CTB]
基于php影视资讯网站管理系统获取(php毕业设计)
图像融合GANMcC学习笔记
测试开发人均年薪30w+?软件测试工程师如何进阶拿到高薪?
Based on php online music website management system acquisition (php graduation design)
Homework 8.1 Orphans and Zombies
方舟:生存进化PVE模式和PVP模式
ARFoundation Getting Started Tutorial U2-AR Scene Screenshot Screenshot
随机推荐
0DFS Medium LeetCode6134. Find the closest node to the given two nodes
365天挑战LeetCode1000题——Day 046 生成每种字符都是奇数个的字符串 + 两数相加 + 有效的括号
Suggestions and answer 8.1 C traps and defect chapter 8
基于php在线学习平台管理系统获取(php毕业设计)
property语法
Shell编程之条件语句
方舟:生存进化PVE模式和PVP模式
Popular explanation: what is a clinical prediction model
多商户商城系统功能拆解19讲-平台端发票管理
HCIP---多生成树协议相关知识点
Unity Shader 常规光照模型代码整理
左旋氧氟沙星/载纳米雄黄磁性/As2O3磁性Fe3O4/三氧化二砷白蛋白纳米球
PX4模块设计之十五:PX4 Log设计
C Expert Programming Chapter 1 C: Through the Fog of Time and Space 1.3 The Standard I/O Library and the C Preprocessor
C语言_联合体共用体引入
Scala练习题+答案
MySQL related knowledge
JS Improvement: Handwritten Publish Subscriber Model (Xiaobai)
groupByKey和reduceBykey的区别
2022-08-01 第五小组 顾祥全 学习笔记 day25-枚举与泛型