要陪纯考虑到0是一个非正非负的特殊偶数
#include
void main()
{
int a[100],i,item,sum1,sum2;
printf("请输入所要输入亩散整数的个数:");
scanf("%d",&item);
printf("请输入%d个整数:\n",item);
for(i=0;i
sum1=sum2=0;
for(i=0;i
if(a[i]==0) continue;//continue是跳过后面语句迅乱氏,直接从下一个循环开始,加速循环
else if(a[i]%2==0)
sum2=sum2+a[i];
else
sum1=sum1+a[i];
}
printf("奇数之和为:%d,偶数之和为:%d\n",sum1,sum2);
}
#include
int main() {
int sum_odd = 0;
int sum_even = 0;
printf 吵盯("Please input integer numbers. -1 to end.\n");
while (1) {
int num = 0;
scanf("%d", &num);
if (num < 0) {
液枝 break;
} else if (num % 2 == 0) {
升埋和 sum_even += num;
} else {
sum_odd += num;
}
}
printf("sum of odd numbers is: %d\n", sum_odd);
printf("sum of event numbers is: %d\n", sum_even);
return 0;
}
#include "困衡stdio.h"
int main()
{
int d,js,os,n;
js=0;
os=0;
n=0;
while(scanf("誉誉%d",&d)!=0)
{
if(d%2==0)
os+=d;
else
js+=d;
n++;
}
printf("奇数和为:%d,偶数和为:%d,共%d个汪虚做数。\n",js,os,n);
}