C语言编程:输入任意个正整数(以输入负数表示结束输入),分别求出所有的奇数之和,所有的偶数之和?

各位大佬求解答,谢谢
2024-11-18 20:28:39
推荐回答(1个)
回答1:

#include

int main() {
int n;
int odd = 0, even = 0;
while ((scanf("%d", &n)) == 1) {
if (n < 0)
break;
if (n % 2)
odd += n;
else
even += n;
}
printf("sumodd=%d sumeven=%d", odd, even);
return 0;
}