C++一维数组的累加怎么算,构造sum函数

2024-11-02 14:33:39
推荐回答(2个)
回答1:

int sum(int a[], int n){
int sum = 0;
for (int i = 0; i < n; i++){
sum += a[i];
}
return sum;
}
void main()
{
int a[] = {1,2 ,3, 4, 5};
printf("%d", sum(a, 5));

}

回答2:

#include 
int main()
{
int x,y;
cin>>x>>y;
cout<return 0;
}