用C语言,有3个整数a,b,c由键盘输入,输出其中最大的数
时间: 2024-06-12 19:08:09 浏览: 18
```c
#include <stdio.h>
int main() {
int a, b, c;
printf("请输入三个整数:\n");
scanf("%d%d%d", &a, &b, &c);
int max = a;
if (max < b) {
max = b;
}
if (max < c) {
max = c;
}
printf("最大的数是:%d\n", max);
return 0;
}
```
说明:
1. 首先定义3个整型变量a、b、c,用于存储从键盘输入的三个整数;
2. 通过scanf函数从键盘依次输入三个整数a、b、c;
3. 定义一个变量max,并将其初始化为a;
4. 使用if语句逐一比较b和c与max的大小,如果比max大,则将max赋值为这个数;
5. 最后输出max即为最大的数。
相关问题
c语言有3个整数a, b, c,由键盘输入,输出其中最大的数
下面是一个示例代码:
```
#include <stdio.h>
int main() {
int a, b, c;
printf("请输入三个整数,以空格分隔:");
scanf("%d %d %d", &a, &b, &c);
int max = a;
if (b > max) {
max = b;
}
if (c > max) {
max = c;
}
printf("最大的数是:%d\n", max);
return 0;
}
```
首先从键盘输入三个整数,然后比较它们的大小,将最大值赋给变量max,最后输出max。在比较大小时,可以使用if语句进行判断,即如果某个数比max大,则更新max的值。
有3个整数a、b、c由键盘输入,输出其中最大的数。用C语言实现
```
#include <stdio.h>
int main() {
int a, b, c;
printf("请输入三个整数,以空格分隔:");
scanf("%d%d%d", &a, &b, &c);
int max = a;
if (b > max) {
max = b;
}
if (c > max) {
max = c;
}
printf("最大的数是:%d\n", max);
return 0;
}
```
相关推荐
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)