引用:
|
作者isamuplus
這個問題很簡單耶,反正輸入的不是奇數就是偶數嘛,你就一邊輸入一邊偷算有幾個
奇數跟偶數,一邊偷算總和...到最後除一除不就出來了...
|
寫出來是這樣 ... 但如何讓他ㄧㄧ列出偶數有哪些 .. 奇數有哪些 ... 我用C去寫
#include<stdio.h>
int main()
{
int number,total1,total2,i,p,j;
float average1,average2;
total1=0;
total2=0;
j=0;
p=0;
while(number!=-1)
{
printf("Enter number,-1 to end \n");
scanf("%d",&number);
i=number%2;
if(i ==0)
{
j=j+1;
total1=total1+number;
}
if(i ==1)
{
p=p+1;
total2=total2+number;
}
}
printf("偶數個數有%d個\n",j);
printf("所有偶數平均=%.2f\n",(float)total1/j);
printf("奇數個數有%d個\n",p);
printf("所有奇數平均=%.2f\n",(float)total2/p);
system("pause");
}