#include<iostream> #include<iomanip> #include<cmath> using namespace std; void fun(int p, int n) { int i; float average = 0, s = 0; for (i = 0; i < n; i++) { average = average + (p + i); } average = average / n; for (i = 0; i < n; i++) { s = s + ((p + i) - average) * ((p + i) - average); } s = s / n; s = sqrt(s); cout << fixed << setprecision(2) << s; } int main() { int a[10], i; int n; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; } fun(a, n); return 0; }有编译错误吗
时间: 2023-11-30 09:04:11 浏览: 145
使用include <iostream>时一定要加using namespace std
有编译错误。
函数fun的第一个参数是int类型,但在主函数中传递的是int数组a,应该修改为以下形式:
```
void fun(int a[], int n)
```
另外,程序中缺少头文件<cmath>。应该加上:
```
#include<cmath>
```
阅读全文