当前位置:网站首页>【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;
}
总结
以上就是该题目三种解法,博主比较钟爱第三种,因为代码简洁,目的性也强,就是要理解三目操作符的用法即可,以后也会更新更多常见题目的解法,尽量做到一题多解,开阔思路,找到最优解,最后,喜欢的话,希望家人们给个一键三连多多支持,博主也多加努力!!
+
关注
+
收藏嗷!!
边栏推荐
- 二分法中等 LeetCode6133. 分组的最大数量
- 基于php动漫周边商城管理系统(php毕业设计)
- PX4模块设计之十五:PX4 Log设计
- 牛血清白蛋白-葡聚糖-叶黄素纳米颗粒/半乳糖白蛋白磁性阿霉素纳米粒的制备
- C expert programming
- 图像融合GANMcC学习笔记
- LeetCode·每日一题·1374.生成每种字符都是奇数个的字符串·模拟
- 包含吲哚菁绿的多聚体白蛋白纳米球/载马钱子碱纳米粒的牛血清白蛋白微球的制备
- File operations of WEB penetration
- Popular explanation: what is a clinical prediction model
猜你喜欢

ORI-GB-NP半乳糖介导冬凌草甲素/姜黄素牛血清白蛋白纳米粒的研究制备方法

LeetCode

Centos7--MySQL的安装

Based on php online learning platform management system acquisition (php graduation design)

19 Lectures on Disassembly of Multi-merchant Mall System Functions - Invoice Management on the Platform

【力扣】字符串相乘

ISC2022 HackingClub white hat summit countdown 1 day!Most comprehensive agenda formally announced!Yuan universe, wonderful!

Shell programming conditional statement

Based on php Xiangxi tourism website management system acquisition (php graduation design)

MySQL相关知识
随机推荐
C Expert Programming Chapter 1 C: Through the Fog of Time and Space 1.1 The Prehistoric Phase of the C Language
Pagoda application experience
2022-08-01 第五小组 顾祥全 学习笔记 day25-枚举与泛型
Centos7--MySQL的安装
FusionGAN:A generative adversarial network for infrared and visible image fusion article study notes
Realize the superposition display analysis of DWG drawing with CAD in Cesium
深拷贝浅拷贝
365天挑战LeetCode1000题——Day 046 生成每种字符都是奇数个的字符串 + 两数相加 + 有效的括号
一个关于操作数据库的建议—用户密码
How to make the timer not execute when the page is minimized?
Interview Blitz 70: What are sticky packs and half packs?How to deal with it?
WEB 渗透之文件类操作
AI应用第一课:支付宝刷脸登录
可视化——Superset使用
AIDL communication
虚拟内存与物理内存之间的关系
scikit-learn no moudule named six
LeetCode·32.最长有效括号·栈·动态规划
shell specification and variables
HCIP---Architecture of Enterprise Network