题解 | #牛牛学数列#
牛牛学数列
https://www.nowcoder.com/practice/0b97367cd2184c12a0e02f7c223aee11
#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; }
C语言基础 文章被收录于专栏
里面较为详细的介绍了c语言的相关用法和有关题目。