题解 | #牛牛学数列#
牛牛学数列
https://www.nowcoder.com/practice/0b97367cd2184c12a0e02f7c223aee11
#include<stdio.h> int main() { int n,i,sum=0,j;//j用来变符号 scanf("%d",&n);//输入整数n for(i=1;i<=n;i++)//i累加到n { j=(i%2==0?-1*i:i);//当i为偶数,j等于i乘-1,当i为奇数,j等于i sum=sum+j;//sum累加会变号的j } printf("%d",sum);//输出sum return 0; }