C++求整型数组的和

#include <iostream>
using namespace std;


int main() {
    int a[5] = { 1, 3, 5, 7, 9 };
    int sm = 0;  //注意这里要给默认值
    for (int i = 0; i < 5; i++) {
        sm += a[i];
        cout << "a[i]=" << a[i] << ", sm=" << sm << endl;
    }
    return 0;
}
posted @ 2020-01-18 17:47  平平无奇小辣鸡  阅读(867)  评论(0编辑  收藏  举报