Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/157.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++ - Fatal编程技术网

C++ 当我试图运行代码时,我得到了第二个输出作为垃圾值。有人能说出那个密码的错误吗

C++ 当我试图运行代码时,我得到了第二个输出作为垃圾值。有人能说出那个密码的错误吗,c++,C++,当我试图运行代码时,我得到了第二个输出作为垃圾值。有人能告诉我那个密码的错误吗 > C和C++中的数组是零基的。运行从0到N-1和T-1的循环 在使用数组值之前,不需要初始化它们。在形式上,您的程序行为是未定义的。(我想你的意思是n[I]=而不是n[I]+=) 像intn[T]这样的可变长度数组是编译器扩展。请记住这一点,因为这可能会影响可移植性 问题是: sample input: 2 3 2 4 5 7 3 8 4 5 7 sample output: 7 0 when the i t

当我试图运行代码时,我得到了第二个输出作为垃圾值。有人能告诉我那个密码的错误吗

<> > C和C++中的数组是零基的。运行从0到N-1和T-1的循环

  • 在使用数组值之前,不需要初始化它们。在形式上,您的程序行为是未定义的。(我想你的意思是
    n[I]=
    而不是
    n[I]+=

  • intn[T]
    这样的可变长度数组是编译器扩展。请记住这一点,因为这可能会影响可移植性

  • 问题是:

    sample input: 2
    3 2
    4 5 7
    3 8
    4 5 7
    sample output:
    7
    0
    
     when the i tried the above code the answer that i got like: 
     input:2
     3 2
     5 6 8
     2 2
     9 1
     output:
     9
     -880625041
    
    这相当于
    n[i]=n[i]+x/K
    因此它使用了一个先验值
    n[i]
    。但是,您还没有为数组
    n
    的元素设置任何先验值。因此,首先将数组初始化为
    0

     n[i]+=x/K;
    
    for(i=0;i您真的应该学会在编译时启用所有警告和调试信息(例如,使用
    g++-Wall-Wextra-g
    )以及如何使用调试器和其他工具(例如,等等)。了解更多信息,使用其标准,如
     n[i]+=x/K;
    
          for(i=0;i<T;i++)
             n[i] = 0;
    
      for(int j=1; j<=N; j++)