C语言编程 求1到100之间奇数之和,1到100之间偶数之和
程序员文章站
2022-03-13 13:40:59
...
/* 1到100之间奇数之和,1到100之间偶数之和 */
include <stdio.h>
int main(void) { int i,j; int sum = 0;
for (i = 1; i <= 100; i+=2)
sum = sum + i;
printf("1到100之间奇数之和为: %d\n", sum);
sum = 0;
for (j = 1; j <= 100; ++j)
{
if (j%2 == 0)
sum = sum + j;
}
printf("1到100之间偶数之和为: %d\n", sum);
return 0;
} `
转载于:https://my.oschina.net/mylaven/blog/1931962