#include <stdio.h> int main() { /*int n = 0;//初始化 scanf("%d", &n);//输入 int i = 0;//遍历 int sum1 = 0;//奇数项 int sum2 = 0;//偶数项 for (i = 1; i <= n; i+=2) { sum1 = sum1 + i; } for (i = 2; i <= n; i+=2) { sum2 = sum2 + i; } int sum = sum1 - sum2;//结果 printf("%d\n", sum);//输出 */ int n = 0;//初始化 scanf("%d", &n);//输入 int i = 0;//遍历 int x = 0;//取出i的值 int sum = 0; for (i = 1; i <= n; i++) { x = i; if (x % 2 == 0) { x *= -1; } sum = sum + x; } printf("%d\n", sum); return 0; }