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