#include "stdio.h"
int main()
{
int count1=0,count2=0,i;
while(1)
{
scanf("%d",&i);
if(i==-1)
break;
else if(i%2==0)
count1++;
else if(i%2==1)
count2++;
}
printf("奇数共有%d个,偶数共有%d个.\n",count2,count1);
}
#include
int main()
{
int even,odd,n;
even=odd=0;
while(scanf("%d",&n)!=EOF)
{
if(n==-1) break;
if(n%2==0) even++;
else odd++;
}
printf("偶数=%d个 奇数=%d个\n",even,odd);
return 0;
}
负数也有奇偶之分,输入的-1也是奇数,0也是特殊偶数
#include
int main()
{
int i;
int a=0,b=0;
scanf("%d",&i);
while(i!=-1)
{
if(i%2==0)a++;
else b++;
scanf("%d",&i);
}
printf("奇数有%d个,偶数有%d个\n",b,a);
}