题解 | #牛牛学数列#
牛牛学数列
https://www.nowcoder.com/practice/0b97367cd2184c12a0e02f7c223aee11
#include <iostream> using namespace std; int main() { int n, sum = 0; scanf("%d", &n); for(int i = 1; i <= n; i++) { if(i%2) sum +=i; //加减数字的规律是看数字的奇偶性,奇数加,偶数减 else sum -= i; } printf("%d", sum); return 0; }