C自学,自己编写的代码,也和网上的比对了,但是程序没法正常运行。求老司机帮忙!谢谢了!
代码如下:// 读取整数,知道用户输入0;打印输入的偶数个数(不包括0;这些偶数的平均值;输入的奇数个数以及奇数个数的平均值。 //
#include<stdio.h>
#include<stdlib.h>
#define TWO 2
int main(void)
{
int num, count_odd=0, count_even=0, sum_odd=0, sum_even=0;
printf("输入整数,并以0结束:\n");
scanf("%d", &num);
while(num != '0')
{
if(num == 0)
break;
if(num % TWO == 0)
{
count_even++;
sum_even+=num;
}
else
{
count_odd++;
sum_odd+=num;
}
printf("请继续输入下一个整数:\n");
scanf("%d", &num);
}
printf("%d %d\n", count_even, (float)sum_even / count_even);
printf("%d %d\n", count_odd, (float)sum_odd / count_odd);
system("pause");
return 0;
}