#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);//输出 return 0; }