Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Anonymous
Anonymous asked in 電腦與網際網路程式設計 · 1 decade ago

c語言 請幫我翻譯題目.....演算法

請幫我翻譯題目(主要)

Write a function qualityPoints that inputs a student's average and

return 4 if a student's average is 90-100,3 if the average is 80-89.2 if

the average is 70-79,1 if the average is 60-69,and 0 if the average is

lower than 60.

以上是題目

以下次參考用

請幫我寫演算法

跟程式語言

不要太難的

用函式寫

感謝

請使用c語言

不要使用c++

Update:

感謝你摟~

因為我只是題目看不太懂..

但是有猜到他的意思

我是個程式初學者

老實說

還沒學到陣列呢

Update 2:

題目看懂了我就可以寫了

1 Answer

Rating
  • ?
    Lv 5
    1 decade ago
    Favorite Answer

    寫一個輸入學生成績,然後傳回學生素質的函式,

    平均90-100 傳回4

    平均80-89 傳回3

    平均70-79 傳回2

    平均60-69 傳回1

    平均不及格 傳回0

    qp函式(double陣列 grade, 陣列大小 size)

    int qualityPoints(double grade[],int size){

    double sum=0;

    int i;

    //求分數總和

    for(i=0;i<size;i++) sum+=grade[i];

    //(sum/size)分數平均

    int pt=(int)((sum/size)/10-5);//落點值5~-5,真正的範圍4~0

    if(pt<0) return 0;//小於最小值,傳回最小值

    if(pt>4) return 4;//大於最大值,傳回最大值

    return pt; //照常傳回

    }

    2008-10-31 22:36:55 補充:

    最後三行如果教過conditional運算子則可用

    return (pt<0)?0:(pt>4)?4:pt;

Still have questions? Get your answers by asking now.