C++编程 从键盘输入5个浮点数,求出其和及平均值。

2024-12-02 09:17:30
推荐回答(5个)
回答1:

以下程序可以在vc6.0当中实现
#include
void
main()
{
float
a,b,c,d,e,average,sum;
cout<<"Input
your
five
number:"<cin>>a>>b>>c>>d>>e;
sum=a+b+c+d+e;
average=sum/(float)5;
cout<<"The
sum
is:"<cout<<"The
average
is:"<}

回答2:

以下程序可以在vc6.0当中实现
#include
void main()
{
float a,b,c,d,e,average,sum;
cout<<"Input your five number:"< cin>>a>>b>>c>>d>>e;
sum=a+b+c+d+e;
average=sum/(float)5;
cout<<"The sum is:"< cout<<"The average is:"<}

回答3:

main
{ float a[5],sum,average;
int i;
for(i=0;i<5;i++)
{scanf("%f",&a[i]);
sum+=a[i];}
average=sum*1.0/8;
printf("和是%f,平均值是%f",sum,average);
}

回答4:

#include
using namespace std;

int main()
{
float a[5];
float sum = 0;
for(int j = 0; j < 5; j++)
{
cout << "请输入第" << j + 1 << "个数据";
cin >> a[j];
}
for(int i = 0; i < 5; i++)
{
sum += a[i];
}
cout << "the sum is " << sum << endl;
cout << "the average is " << sum/5 << endl;
return 0;
}

回答5:

程序
vc6.0
实现
#include
void
main()
{
float
a,b,c,d,e,average,sum;
cout<<"Input
your
five
number:"<cin>>a>>b>>c>>d>>e;
sum=a+b+c+d+e;
average=sum/(float)5;
cout<<"The
sum
is:"<cout<<"The
average
is:"<}