用户从键盘输入的三个整数,并输出最大值和最小值,c++语言表示
时间: 2024-05-08 20:17:14 浏览: 126
```
#include <stdio.h>
int main() {
int a, b, c;
printf("请输入三个整数:");
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,最小值:%d\n", max, min);
return 0;
}
```
相关问题
c++代码,从键盘输入三个整数,输出其中的最小值和最大值
以下是实现该功能的 C++ 代码:
```c++
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cout << "请输入三个整数:" << endl;
cin >> a >> b >> c;
int maxNum = a;
if (b > maxNum) {
maxNum = b;
}
if (c > maxNum) {
maxNum = c;
}
cout << "最大值为:" << maxNum << endl;
int minNum = a;
if (b < minNum) {
minNum = b;
}
if (c < minNum) {
minNum = c;
}
cout << "最小值为:" << minNum << endl;
return 0;
}
```
程序中首先使用 `cin` 从键盘输入三个整数 `a`、`b`、`c`,接着使用条件语句找出其中的最大值和最小值,并输出结果。
从键盘输入3个整数,输出其中的最大值、最小值和平均值。c++
#include<stdio.h>
int main()
{
int a,b,c,max,min;
float avg;
printf("请输入3个整数:");
scanf("%d%d%d",&a,&b,&c);
max=a>b?a:b; // 求最大值
max=max>c?max:c;
min=a<b?a:b; // 求最小值
min=min<c?min:c;
avg=(float)(a+b+c)/3; // 求平均值
printf("最大值:%d\n最小值:%d\n平均值:%.2f\n",max,min,avg);
return 0;
}
阅读全文
相关推荐
![](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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)