//程序讀取整數,直到輸入0.輸入終止後,報告輸入的偶數(不包括0)總個數,偶數的平均值,輸入的奇數總個數以及奇數的平均值
#include<stdio.h>
int main (void)
{
int num, en, on; //num是檢測輸入的數,en是偶數個數,on是奇數個數
float aen = 0, aon = 0; //aen是偶數的平均值,aon是奇數的平均值
printf("Please enter your numbers:\n");
scanf("%d", &num);
whlie(0 != num)
{
if (0 == num % 2){ //能被2整除,是偶數
en++;
aen = aen + num;
}
else{ //不能被2整除,是奇數
on++;
aon = aon + num;
}
scanf("%d", &num);
}
printf("There are %d even numbers,%d odd numbers.\n",
en, on);
printf("The averge of even numebrs is %.2lf.The averge of odd numbers is %.2lf.\n",
aen/en, aon/on);
printf("Done\n");
return 0;
}
變量en,on沒有初始化,while循環單詞拼錯了