C++语言中怎么输入3个非整数数字,分别列出平均值,大于平均值,小于平 ...
发布网友
发布时间:2024-05-29 13:26
我来回答
共2个回答
热心网友
时间:2024-06-11 13:30
//将比较的代码写成函数,调用三次
#include <iostream>
using namespace std;
int main()
{
double number1,number2,number3, average;
cout << "Enter a number ";
cin >>number1>>number2>>number3;
average = (number1 + number2 + number3) / 3;
cout << "The average is " << average<<endl;
Judge(number1,average);
Judge(number2,average);
Judge(number3,average);
return 0;
}
void Judge(double x,double average)
{
if (x< average)
cout << "The number that is less than the average is " << x<<endl;
else if (x > average)
cout << "The number that is greater than the average is " << x<< endl;
else if (x = average)
cout << "The number that is equal to the average is " << x<<endl;
}
热心网友
时间:2024-06-11 13:31
将输入的三个数字写成数组的形式
#include<iostream.h>
using namespace std;
int main()
{
double a[2];
for(int i=0;i<2;i++)
cin>>a[i];
double average=0;
average+=a[i];
average/=3;
for(i=0;i<2;i++)
{
if(a[i]>average)
cout<<
if(a[i]<arvrage)
cout<<
if(a[i]=average)
cout<<
}
c语言中输入三个数,输出和及平均值
include <stdio.h>void main(){float a,b,c;scanf("%f%f%f",&a,&b,&c);printf("和:%f\n平均数:%f",a+b+c,(a+b+c)/3);}//运行示例:
c语言,输入3个数求他们的平均值并输出,
printf("c=");scanf("%d",&c);average=(a+b+c)/3;printf("a,b,c3个数字的平均值:%d",average);}
输入3个双精度实数,分别求出它们的和、平均值、平方和以及平方和的开方...
printf ("(%g+%g+%g)/3=%g,A+B+C的平均值为%g\n",a,b,c,(a+b+c)/3,(a+b+c)/3);printf ("%g^2+%g^2+%g^2=%g\n",a,b,c,a*a+b*b+c*c);printf ("%g^2+%g^2+%g^2的开跟为%g\n",a,b,c,sqrt(a*a+b*b+c*c));return 0;} ...
C语言求平均值:输入三个数,求平均值
void main(){ int a,b,c;double d;printf("请输入3个整数:");scanf("%d%d%d",&a,&b,&c);d=(a+b+c)/3;printf("%lf",d);} C程序中函数的数目实际上是不限的,如果说有什么限制的话,那就是,一个C程序中必须至少有一个函数,而且其中必须有一个并且仅有一个以main为名的函数...
编写程序,从键盘上输入3个数,分别给变量a,b,c,求它们的平均值.
include <stdio.h>void main(){ int i; float sum = 0; float v; printf("输入3个数\n"); for(i=0;i<3;i++) { scanf(%f", &v); sum += v; } printf("平均值为%f\n", sum/3);}
在c++语言中输入3个双精度实数,分别求出它们的和、平均值、平方和并...
include <iostream> using namespace std;void main() { double a,b,c,s,av,ss;cin>>a>>b>>c;s=a+b+c;av=s/3;ss=a*a+b*b+c*c;cout<<s<<","<<av<<","<<ss<<endl;}
C语言 编写程序,输入3个实数,求其平均值并取两位小数后进行四舍五入...
回答:#include"stdio.h" #include"math.h" void main() { int i,j=NULL,a[3]; float aver1,aver=NULL,j1,j2; clrscr(); for(i=0;i<3;i++) scanf("%d",&a[i]); aver1=(a[0]+a[1]+a[2])/3.0; j=aver1; j1=aver1-j; if(j1*10>5) aver=aver1+1; j2=aver...
...从键盘输入十个数,计算其平均值,并将大于平均值的数输出
int main(){ int n, i;float num[100], sum = 0.0, average;printf("输入元素个数: ");scanf("%d", &n);while (n > 100 || n <= 0){ printf("Error! 数字需要在1 到 100 之间。\n");printf("再次输入: ");scanf("%d", &n);} for(i = 0; i < n; ++i){ print...
输入3个整数,输出它们的平均值,保留3位小数。用C语言(C-free)来写,求...
include <stdio.h> main(){ int a,b,c;double avg = 0.0;scanf("%d%d%d",&a,&b,&c);avg = (a + b + c) / 3;printf("%.3f",avg);
请用C语言编写,输入十几个离散数字,求出平均值及平均极差(极差就是第一...
原式数据:28.41 23.31 20.37 18.04 25.23 10.52 18.45 36.23 35.64 10.64 极差数据:5.10 2.94 2.33 -7.19 14.71 -7.93 -17.78 0.59 25.00 低于UCL:10.52 10.64 高于UCL:36.23 35.64 低于LCLR:-7.19 -7.93 -17.78 高于UCLR:14...