参考代码:
#include<iostream> #include<stdio.h> using namespace std; int main() { int n; cin >> n; int sum = 0; float res = 0; int m = n; while(n--) { int t; cin >> t; sum += t; } printf("%.2f", (float)sum / m); return 0; }
0.0分
6 人评分
#include<iostream> #include<vector> using namespace std; //#include<cstdio> //#include<math.h> int main(){ int n,s = 0; double ave; cin >> n; if(n < 1 || n > 100) return 1; vector<int> a(n); for(int i = 0; i < n; i++){ cin >> a[i]; if(a[i] < 15 || a[i] > 25) return 1; s += a[i]; } ave = (double)s / n; printf("%.2f",ave); return 0; }这样为什么错啦
DSTJZ 2024-01-06 22:08:59 |
兄弟你去看一下vector容器的教程,你用错了