从键盘输入三个整数,输出这三个整数的和、平均值(保留2位小数)、积、最小值以及最大值。
来源:百度知道 编辑:UC知道 时间:2024/05/24 16:47:05
#include<iostream.h>
void main()
{
int x,y,z,sum,product,max,min;
double average;
cout<<"x,y,z=";
cin>>x>>y>>z;
sum = x + y + z;
product = x * y * z;
average = ((int)(sum / 3.0 * 100)) / 100.0; //保留两位小数
max = (x > y) ? (x > z ? x : z) : (y > z ? y : z);
min = (x < y) ? (x < z ? x : z) : (y < z ? y : z);
cout<<"和:"<<sum<<endl
<<"积:"<<product<<endl
<<"平均数:"<<average<<endl
<<"最大值:"<<max<<endl
<<"最小值:"<<min<<endl;
}
将三个数全部选中,
再看屏幕右下角可知三个数的和与平均数
利用排序功能得出最大值和最小值
将三个数全部选中,看屏幕右下角可知三个数的和与平均数
利用排序功能得出最大值和最小值
#include<iostream.h>后面有错