Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 阵列函数输出错误_C++_Arrays_Function - Fatal编程技术网

C++ 阵列函数输出错误

C++ 阵列函数输出错误,c++,arrays,function,C++,Arrays,Function,我想要数组元素的平方根,但输出是如此错误!!! 你能帮我纠正我的错误吗??? 如何将阵列更改为大小100 #include <math.h> #include <iostream> using namespace std; // function declaration: double sqrootx(int arr[], int size); int main () { // an int array

我想要数组元素的平方根,但输出是如此错误!!! 你能帮我纠正我的错误吗??? 如何将阵列更改为大小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;
    }
#包括
#包括
使用名称空间std;
//功能声明:
双sqrootx(int-arr[],int-size);
int main()
{
//包含5个元素的整数数组。
双平衡[5]={1000,2,3,17,50};
双sqr;
//将指向数组的指针作为参数传递。
sqr=功率(平衡,5);
//输出返回的值

你可以把你的数字提高到5的幂。平方根是5的幂

for (int i = 0; i < 5; i++) {
    sqr = pow(balance[i], .5);
    cout << " result" << sqr << endl;
}
for(int i=0;i<5;i++){
sqr=功率(余额[i],.5);
cout看起来像一个打字错误:

sqr= sqrootx( balance, 5 ) ;

为了创建大小为100的数组,只需更改
双倍余额[5];
双倍余额[100];

尽管如此,手动输入100个数字是非常困难的。 因此,您需要运行一个循环

根据给定的代码判断,让我们列出代码中缺少的内容

  • 一个循环,用数字填充数组中的每个框
  • pow函数本身。(既然您已经声明了math.h,请使用sqrt
  • 另一个循环(迭代)或递归,用平方根值替换数组中的原始数字
  • 用于显示所有值均为平方根的数组的循环或函数
  • 一些预定义的条件,如“负值”或一些用于绝对值的代码位

  • 希望这能有所帮助。

    你的代码真的没有任何意义。我们也不知道你想做什么,或者你希望得到什么输出。例如,函数
    sqrootx
    应该用它的平方根替换数组中的每个条目吗?如果是,为什么它会返回一个
    double
    ?我想知道数组的输出应该是什么y的能力…?你必须把每一个元素都放在pow()中,而不是整个数组指针这家伙是你的同学吗?如果你没有给我们看函数的代码,你希望我们如何诊断
    sqrootx
    的故障?我想调用sqrt是一种更干净的方法