题解 | #牛牛学数列#
牛牛学数列
https://www.nowcoder.com/practice/0b97367cd2184c12a0e02f7c223aee11
#include <stdio.h> int main() { int a,count=-1; scanf("%d",&a); int i,sum=0; for(i=1;i<=a;i++) { sum+=i*(count*=-1); } printf("%d\n",sum); return 0; }
牛牛学数列
https://www.nowcoder.com/practice/0b97367cd2184c12a0e02f7c223aee11
#include <stdio.h> int main() { int a,count=-1; scanf("%d",&a); int i,sum=0; for(i=1;i<=a;i++) { sum+=i*(count*=-1); } printf("%d\n",sum); return 0; }
相关推荐