關(guān)于平均值不精確
#include <stdio.h>
int zongfen(int score[])
? ? {
? ? ? ? int sum;
? ? ? ? int i;
? ? ? ? for(i=0;i<10;i++)
? ? ? ? {
? ? ? ? ? ? sum += score[i];
? ? ? ? }
? ? return sum;
? ? }
int zgf(int score[])
? ? {
? ? ? ? int i;
? ? ? ? int up=0;
? ? ? ? for(i=0;i<10;i++)
? ? ? ? {
? ? ? ? ? ? if(score[i]>up)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? up=score[i];
? ? ? ? ? ? }
? ? ? ? }
? ? return up;
? ? }
int zdf(int score[])
? ? {
? ? ? ? int i;
? ? ? ? int down=100;
? ? ? ? for(i=0;i<10;i++)
? ? ? ? {
? ? ? ? ? ? if(score[i]<down)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? down = score[i];
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? return down;
? ? }
void Dd(int score[])
? ? {
? ? ? ? int i,j;
? ? ? ? for(i=8;i>=0;i--)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? for(j=0;j<=i;j++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? if(score[j]>score[j+1])
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? int a;
? ? ? ? ? ? ? ? ? ? ? ? a = score[j];
? ? ? ? ? ? ? ? ? ? ? ? score[j]=score[j+1];
? ? ? ? ? ? ? ? ? ? ? ? score[j+1]=a;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? }
int main()
{
? ? int score[10]={67,98,75,63,82,79,81,91,66,84};
? ? int sum = zongfen(score);
? ? printf("考試總分是:%d\n",sum);
? ? int up = zgf(score);
? ? printf("考試最高分是:%d\n",up);
? ? int down = zdf(score);
? ? printf("考試最低分是:%d\n",down);
? ? float Ag = sum/10;
? ? printf("考試平均分是:%f\n",Ag);//這里為什么是.000000而不是.600000?
? ? printf("考試成績降序:");
? ? Dd(score);
? ? int i;
? ? for(i=9;i>=0;i--)
? ? ? ? {
? ? ? ? ? ? if(i!=0)
? ? ? ? ? ? {
? ? ? ? ? ? printf("%d,",score[i]);
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? printf("%d",score[i]);
? ? ? ? }
? ? return 0;
}
2018-07-30
float Ag = (float)sum/10;在計算之前先強(qiáng)制轉(zhuǎn)換一下sum的類型
2018-07-28
平均值最后取值78.00000為什么不是78.600000?
直接代入總分函數(shù)算的話為什么取值是79.000000?