题解 | #求 1 - n 之间偶数的和#
求 1 - n 之间偶数的和
https://www.nowcoder.com/practice/03df7fa0950046a9ba564b4438f918a3
#include <iostream> using namespace std; int main() { int n; cin >> n; int sum = 0; // write your code here...... int i = 0; for (i = 0; i <= n; i++) { if (0 == (i % 2)) sum += i; } cout << sum << endl; return 0; }