输入三个数,输出最大值,用C
时间: 2023-12-13 14:05:58 浏览: 45
当然可以,下面是一个实现输入三个数,输出最大值的C语言程序:
```c
#include <stdio.h>
int main() {
float num1, num2, num3, max_num;
printf("请输入第一个数: ");
scanf("%f", &num1);
printf("请输入第二个数: ");
scanf("%f", &num2);
printf("请输入第三个数: ");
scanf("%f", &num3);
max_num = num1;
if (num2 > max_num) {
max_num = num2;
}
if (num3 > max_num) {
max_num = num3;
}
printf("最大数为: %.2f", max_num);
return 0;
}
```
这个程序会依次输入三个数,然后比较它们的大小,找到最大值并输出。注意,这个程序中使用了 `scanf` 函数来实现输入,使用了 `printf` 函数来实现输出。
相关问题
c语言输入三个数输出最大值
```c
#include <stdio.h>
int main() {
int a, b, c, max;
printf("请输入三个数:");
scanf("%d %d %d", &a, &b, &c);
max = a;
if (b > max) {
max = b;
}
if (c > max) {
max = c;
}
printf("最大值为:%d\n", max);
return 0;
}
```
用C语言编一个输入三个数输出最大值和最小值
好的,以下是用C语言编写一个输入三个数,输出最大值和最小值的程序:
```c
#include <stdio.h>
int main() {
int a, b, c;
printf("请输入三个数:\n");
scanf("%d%d%d", &a, &b, &c);
int max = a > b ? (a > c ? a : c) : (b > c ? b : c);
int min = a < b ? (a < c ? a : c) : (b < c ? b : c);
printf("最大值为:%d\n", max);
printf("最小值为:%d\n", min);
return 0;
}
```
其中,首先使用 `scanf` 函数获取用户输入的三个数,然后通过三目运算符和比较运算符求出最大值和最小值,最后输出结果。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
![](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)