以下程式碼
sum1 = grade[0][0] + grade[0][1] + grade[0][2];
ave1 = sum1/3;
sum2 = grade[1][0] + grade[1][1] + grade[1][2];
ave2 = sum2/3;
sum3 = grade[2][0] + grade[2][1] + grade[2][2];
ave3 = sum3/3;
sum4 = grade[3][0] + grade[3][1] + grade[3][2];
ave4 = sum4/3;
sum5 = grade[4][0] + grade[4][1] + grade[4][2];
ave5 = sum5/3;
改成
sum1 = grade[0][0] + grade[0][1] + grade[0][2];
ave1 =(float) sum1/3;
sum2 = grade[1][0] + grade[1][1] + grade[1][2];
ave2 = (float)sum2/3;
sum3 = grade[2][0] + grade[2][1] + grade[2][2];
ave3 = (float)sum3/3;
sum4 = grade[3][0] + grade[3][1] + grade[3][2];
ave4 = (float)sum4/3;
sum5 = grade[4][0] + grade[4][1] + grade[4][2];
ave5 = (float)sum5/3;
試試看
記得最後要printf的時候,要把%d改成%f應該就可以了吧
|