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