第1个回答 2015-05-16
#include <stdio.h>
#define UINT unsigned int
int main(void){
UINT temp=0;
UINT ou=0,ji=0;
UINT sum=0;
UINT count=0;
while(puts("输入一个正整数 若要中止请输入0"),scanf("%u",&temp),temp!=0){
count++;
sum+=temp;
(temp%2==1)?ji++:ou++;
while(getchar()!='\n'); //清空缓冲区
}
if (count!=0){
printf("奇数%u个\t偶数%u个\n平均 %.3f\n",ji,ou,(float)sum/count);
}
return 0;
}本回答被网友采纳
第2个回答 2017-08-28
#include<stdio.h>
void main() { int n,i,a,b,x; float av;
i=0; av=0; a=b=0;
while ( 1 ) {
scanf("%d",&x); if ( x==0 ) break;
av+=x; if ( x%2==0 ) a++; else b++;
i++;
}
if ( i ) av/=i;
printf("平均值为%f,偶数%d,奇数%d。\n",av,a,b);
}