求和
int sum = 0, val = 1; while (val<=10) { sum += val; val++; } cout << "Sum of 1 to 10 inclusive is " << sum << endl; return 0;
int length, i, sum = 0; cout << "输入一个数,从一开始相加 " << endl; cin >> length; for (int i = 0; i <= length; i++) { sum += i; } cout << sum << endl;