📜  C程序计算奇数和偶数之和 - C编程语言代码示例

📅  最后修改于: 2022-03-11 15:04:36.535000             🧑  作者: Mango

代码示例1
#include void main(){int i, number, odd_sum = 0, even_sum = 0;printf("Enter the value of number\n");scanf("%d", &number);for (i = 1; i <= number; i++){if (i % 2 == 0)even_sum = even_sum + i;elseodd_sum = odd_sum + i;}printf("Sum of all odd numbers = %d\n", odd_sum);printf("Sum of all even numbers = %d\n", even_sum);}