當前位置:編程學習大全網 - 源碼下載 - 壹個班有若幹個學生,***學習5門課程。找出平均成績在90分以上或全部課程成績在85分以上的優秀學生。

壹個班有若幹個學生,***學習5門課程。找出平均成績在90分以上或全部課程成績在85分以上的優秀學生。

我幫妳寫了個,應該對妳有幫助。

#define AVERAGE_SCORE (90)

#define PER_SCORE (85)

typedef struct student

{

int iNum;

float fScore[5];

}STUDENT_ST;

int g_aSatisfy[100] = {0};

int InputPerStuInfo(int iNum, STUDENT_ST *pstStu)

{

printf("Input the %dst student num, math, Eng,c++,linearity and PE:\r\n", iNum+1);

scanf("%d%f%f%f%f%f", &pstStu->iNum,&pstStu->fScore[0], &pstStu->fScore[1], &pstStu->fScore[2],&pstStu->fScore[3],&pstStu->fScore[4]);

return 0;

}

float Average(STUDENT_ST stStu)

{

float fAver = 0;

int i = 0;

while (i<5)

{

fAver += (stStu.fScore[i]/5);

i++;

}

return fAver;

}

int Query(STUDENT_ST *pstStu)

{

int i = 0;

float fAver = 0.0;

while (pstStu[i].iNum != 0)

{

fAver = Average(pstStu[i]);

if (fAver >= AVERAGE_SCORE ||

(pstStu[i].fScore[0] >= PER_SCORE && pstStu[i].fScore[1] >= PER_SCORE

&& pstStu[i].fScore[2] >= PER_SCORE && pstStu[i].fScore[3] >= PER_SCORE && pstStu[i].fScore[4] >= PER_SCORE))

{

g_aSatisfy[i] = 1;

}

else

{

g_aSatisfy[i] = 0;

}

i++;

}

return 0;

}

int main()

{

int iStuSumNum = 0;

int i = 0;

STUDENT_ST astStu[100];

memset(astStu, 0x00, 100*sizeof(STUDENT_ST));

memset(g_aSatisfy, 0x00, 100*sizeof(int));

printf("Please input the total num of students:");

scanf("%d", &iStuSumNum);

for (i=0; i< iStuSumNum; i++)

{

InputPerStuInfo(i, &astStu[i]);

}

Query(astStu);

for (i=0; i< 100;i++)

{

if (1 == g_aSatisfy[i])

{

printf("Satisfy num=%d averg score=%f\r\n", astStu[i].iNum, Average(astStu[i]));

}

}

return 0;

}

下面是程序的執行結果:

Please input the total num of students:3

Input the 1st student num, math, Eng,c++,linearity and PE:

1001 90 90 90 90 89

Input the 2st student num, math, Eng,c++,linearity and PE:

1002 70 100 100 100 95

Input the 3st student num, math, Eng,c++,linearity and PE:

1003 85 85 84 85 85

Satisfy num=1001 averg score=89.800003

Satisfy num=1002 averg score=93.000000

  • 上一篇:qq華夏魔化林海爆什麽
  • 下一篇:新零售電商分銷系統開發費用多少
  • copyright 2024編程學習大全網