题解 | #牛牛学数列#
牛牛学数列
https://www.nowcoder.com/practice/0b97367cd2184c12a0e02f7c223aee11
#include <stdio.h> int main() { int flag = 1, i = 0, n = 0, sum = 0; scanf("%d", &n); for (i = 1; i <= n; i++) { sum = sum + flag * i; flag = -flag; } printf("%d", sum); return 0; }