#import <Foundation/Foundation.h>
int main(int argc, char *argv[])
{
@autorelease
{
int evenSum = 0, oddSum = 0, evenCount = 0, oddCount = 0;
int num;
scanf ("%d", &num);
while (num != 0)
{
if (num > 0)
{
if (num % 2 == 0)
{
evenCount ++;
evenSum += num;
}
else
{
oddCount ++;
oddSum += num;
}
}
else
{
printf("输入有误请重新输入!\n");
}
scanf ("%d", &num);
}
if (evenCount != 0)
printf("偶数个数为:%d 偶数平均值为:%.2f\n", evenCount, (double)evenSum/evenCount);
if (oddCount != 0)
printf("奇数个数为:%d 奇数平均值为:%.2f\n", oddCount, (double)oddSum/oddCount );
}
return 0;
} |