【发布时间】:2012-12-10 14:41:02
【问题描述】:
我想要数组元素的平方根,但输出太错误了!!! 你能帮忙纠正我的错误吗??? 如何将数组更改为 100 的大小?
#include <math.h>
#include <iostream>
using namespace std;
// function declaration:
double sqrootx(int arr[], int size);
int main ()
{
// an int array with 5 elements.
double balance[5] = {1000, 2, 3, 17, 50};
double sqr;
// pass pointer to the array as an argument.
sqr= pow( balance, 5 ) ;
// output the returned value
cout << " result" << sqr << endl;
return 0;
}
【问题讨论】:
-
你的代码真的没有任何意义。我们也不知道您要做什么或您期望的输出。例如,函数
sqrootx是否应该用平方根替换数组中的每个条目?如果是这样,为什么它会返回一个double? -
我想知道阵列的力量应该输出什么......?
-
你必须把每个元素都放在 pow() 中,而不是整个数组指针
-
如果您没有向我们展示函数代码,您希望我们如何诊断
sqrootx的故障?