makeway @ 2024-08-09 20:42:50
#include<bits/stdc++.h>
using namespace std;
int main()
{
int b;
double c=0,d;
cin>>b;
double a[b];
for(c;c<=b;c++){
cin>>a[b];
d+=a[b];
}
cout<<fixed<<setprecision(2)<<d/b<<endl;
return 0;
}
by Eva_91418 @ 2024-08-09 20:46:48
d的初始化)
by Eva_91418 @ 2024-08-09 20:47:01
@makeway
by GoodLuckCat @ 2024-08-09 20:47:38
数组定义大小要是常量
by GoodLuckCat @ 2024-08-09 20:48:20
虽然有的编译器可以卡过但是还是要小心
by Eva_91418 @ 2024-08-09 20:48:46
double a[b];
不能这么定义 应该改成
double a[105];
by GoodLuckCat @ 2024-08-09 20:49:31
@makeway 给你改了一下
#include<bits/stdc++.h>
using namespace std;
int main()
{
int b;
double c=0,d=0;
cin>>b;
double a[b+1];
for(c;c<b;c++){
cin>>a[b];
d+=a[b];
}
cout<<fixed<<setprecision(2)<<d/b<<endl;
return 0;
}
by Eva_91418 @ 2024-08-09 20:49:48
cin>>a[b];
理论上 是a[ c ] 吧
by GoodLuckCat @ 2024-08-09 20:52:41
这个程序有点奇怪,为什么它要专门开一个数组记录一个变量
by makeway @ 2024-08-09 20:53:35
@Eva_81418这是我写的小程序,数组是变量啊。 ```cpp if(g==1){ cout<<" ______\n"; cout<<" |平均分计算|\n"; cout<<"  ̄ ̄ ̄ ̄ ̄ ̄\n"; cout<<"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁\n"; cout<<"|输入保留小数位数:"; cin>>a; cout<<fixed<<setprecision(a); cout<<"|平均分计算(输入分数个数):"; cin>>c; double d[c]; cout<<"|输入分数组(中间用空格隔开):"; for(e;e<=c;++e){ cin>>d[c]; b+=d[c];} cout<<"|平均分是:"<<b/c<<endl; cout<<"▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔\n";}
by makeway @ 2024-08-09 20:55:05
cout<<"|输入保留小数位数:";
cin>>a;
cout<<fixed<<setprecision(a);
cout<<"|平均分计算(输入分数个数):";
cin>>c;
double d[c];
cout<<"|输入分数组(中间用空格隔开):";
for(e;e<=c;++e){
cin>>d[c];
b+=d[c];}
cout<<"|平均分是:"<<b/c<<endl;