Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/64.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语言中带for循环的数组求和_C_For Loop - Fatal编程技术网

C语言中带for循环的数组求和

C语言中带for循环的数组求和,c,for-loop,C,For Loop,我想将这个数组从b[0]到b[42]求和,但它不起作用。有人能帮我吗?这是我的代码: #include <stdio.h> int main() { int b[43] = { 327, 351, 86, 24, 812, 347, 813, 1155, 1049, 378, 370, 837, 1051, 455, 1153, 470, 265, 156, 718, 1284, 1094, 1052, 1204, 116, 1182, 40, 920, 281, 475,

我想将这个数组从
b[0]
b[42]
求和,但它不起作用。有人能帮我吗?这是我的代码:

#include <stdio.h>

int main() {
    int b[43] = { 327, 351, 86, 24, 812, 347, 813, 1155, 1049, 378, 370, 837, 1051, 455, 1153, 470, 265, 156, 718, 1284, 1094, 1052, 1204, 116, 1182, 40, 920, 281, 475, 993, 782, 1053, 17, 332, 846, 1021, 379, 121, 157, 96, 663, 175, 1061 };
    int i;
    int sum = 0;

    for (i = 0; i < 43; ++i) {
        sum += b[i];
    }
    printf("%d", &sum);
    return 0;
}
#包括
int main(){
int b[43]={327、351、86、24、812、347、813、1155、1049、378、370、837、1051、455、1153、470、265、156、718、1284、1094、1052、1204、116、1182、40920、281、475、993、782、1053、17332、846、1021、379、121、157、96、663、175、1061};
int i;
整数和=0;
对于(i=0;i<43;++i){
总和+=b[i];
}
printf(“%d”,和);
返回0;
}

错误在
printf(“%d”和&sum)
您不应该使用
&
符号。将其替换为
printf(“%d”,sum)
应该可以。请在
printf
printf(“%d”和&sum)中查看用法/

sum
和非
&sum
->
printf(“%d”,总和)