编写一个程序,输入三个整数a、b、c,计算并输出a、b、c三个数之间的最大值和最小值。
时间: 2024-02-24 20:26:48 浏览: 64
可以使用以下代码实现:
```
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cout << "请输入三个整数: ";
cin >> a >> b >> c;
// 计算最大值和最小值
int max_num = a;
int min_num = a;
if (b > max_num) {
max_num = b;
}
if (c > max_num) {
max_num = c;
}
if (b < min_num) {
min_num = b;
}
if (c < min_num) {
min_num = c;
}
// 输出最大值和最小值
cout << "最大值为:" << max_num << endl;
cout << "最小值为:" << min_num << endl;
return 0;
}
```
运行程序后,输入三个整数,程序会计算并输出它们的最大值和最小值。
相关问题
编写一个程序,输入a、b、c三个整数,输出其中最大值 使用c语言代码
以下是使用C语言编写的程序,可以输入a、b、c三个整数,然后输出其中的最大值:
```
#include <stdio.h>
int main() {
int a, b, c;
printf("请输入a、b、c三个整数:\n");
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;
}
```
以上程序会在屏幕上显示一个提示,要求用户输入三个整数a、b、c。然后程序会比较a、b、c的大小,找到最大值并将其输出。
用c语言编写一个程序,要求输入a,b,c三个整数,输出其中的最大值
您好,我可以回答这个问题。以下是用 C 语言编写的程序,可以输入三个整数 a、b、c,然后输出其中的最大值:
```
#include <stdio.h>
int main() {
int a, b, c;
printf("请输入三个整数:\n");
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 ;
}
```
希望能对您有所帮助。
相关推荐
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![c](https://img-home.csdnimg.cn/images/20210720083646.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)