【发布时间】:2020-11-23 07:52:47
【问题描述】:
我必须编写一个代码来打印数组中数字的平均值。对于 sum,我使用了一个我在另一个时间使用的函数来计算递归和,然后只除以 n。但它不起作用。
我为什么要这样做?
int aveg(int *a, int n){
if (n == 0){
return 0;
}
else{
return ((aveg(a, n - 1) + a[n-1]) /n);
}
}
【问题讨论】:
-
"it doesn't work" 是一个无用的问题描述。它不会编译吗?它会崩溃吗?它会给出错误的结果吗?你有没有调试过 问题?
-
@MartinR 所说的。另外,修复minimal reproducible example