C語言的提題 有關 while or for給20點....

不知道從何下手....

temperature.out

Please enter the temperatures (Ctrl-D to end).

55 62 68 74 59 45 41 58 60 67 65 78 82 88 91

92 90 93 87 80 78 79 72 68 61 59

There were 6 cold days, 14 pleasant days, and 6 hot days.

The average temperature was 71.2 degrees.

hot day.. 多於85

pleasant day.. 60~84

cold day.. 少於 60

這又這麼寫呢??

1 Answer

Rating
  • 3M
    Lv 6
    1 decade ago
    Favorite Answer

    #include<stdio.h>

    int main(){

    int cold,hot,pleasant,days,tmp;

    double avg=0.0;

    cold=hot=pleasant=days=0;

    while((scanf("%d",&tmp))!=NULL){

    avg+=tmp;

    days++;

    if(day>=85)

    hot++;

    else if(day>=60)

    pleasant++;

    else

    cold++;

    }

    prinf("There were %d cold days, %d pleasant days, and %d hot days.\nThe average temperature was %lf degrees.\n",cold,pleasant,hot,avg/days);

    return 0;

    }

    2009-02-03 11:54:29 補充:

    int main(){

    int cold,hot,pleasant,days,tmp;

    double avg=0.0;

    cold=hot=pleasant=days=0;

    while((scanf("%d",&tmp))!=NULL){

    avg+=tmp;

    days++;

    if(tmp>=85)

    hot++;

    else if(tmp>=60)

    pleasant++;

    else

    cold++;

    }

    2009-02-03 11:54:35 補充:

    printf("There were %d cold days, %d pleasant days, and %d hot days.\nThe average temperature was %.1lf degrees.\n",cold,pleasant,hot,avg/days);

    system("PAUSE");

    return 0;

    2009-02-03 11:56:10 補充:

    很抱歉~

    我第一次PO的bug還滿多的= ="(當時被人趕著打完~)

    請看我補充的即可~

    還要include 2個標頭檔 stdio.h & stdlib.h

    2009-02-03 12:26:30 補充:

    那個~ NULL 的地方 改成 EOF

    謝謝!!

Still have questions? Get your answers by asking now.