#include <stdio.h>
#define ARR_SIZE 30
/************Begin***********/
//此處加上輸入學生資訊的函式宣告
/************End*************/
int main(void)
{
int n;
float score[ARR_SIZE];
long num[ARR_SIZE];
printf("Please enter num and score until score<0:\n");
/************Begin***********/
//此處加上函式呼叫
/************End*************/
printf("Total students:%d\n", n);
return 0;
}
//函式功能:從鍵盤輸入一個班學生某門課的成績及其學號
//當輸入成績為負值時,輸入結束,函式回傳學生總數
/************Begin***********/
/************End*************/


uj5u.com熱心網友回復:
第一關:
#include <stdio.h>
#define ARR_SIZE 30
/************Begin***********/
//此處加上輸入學生資訊的函式宣告
int PrintArr(float *score, long *num);
/************End*************/
int main(void)
{
int n;
float score[ARR_SIZE];
long num[ARR_SIZE];
printf("Please enter num and score until score<0:\n");
/************Begin***********/
//此處加上函式呼叫
n = PrintArr(score, num);
/************End*************/
printf("Total students:%d\n", n);
return 0;
}
int PrintArr(float *score, long *num)
{
int i = 0, n = 0;
while (1)
{
scanf("%ld%f", &num[i], &n);
if (n >= 0)
{
score[i] = n;
i++;
if (i>=ARR_SIZE)
break;
}
else
{
break;
}
}
return i;
}
第二關:自己寫吧,思路如下
1. 2 宣告兩個變數作為計數器, 比如m = 0; x = 0; 遍歷陣列,如果成績小于60,計數器 m++;同時列印學號; 如果成績大于等于60,計數器 x++,同時列印學號。陣列遍歷完成后列印 m, x。
3. 宣告一個臨時int temp[5], 然后就是遍歷陣列加判斷了,
if (score[i] < 60)
temp[0]++;
else if (score[i] >= 60 && score[i] < 70)
temp[1]++;
else if (score[i] >= 70 && score[i] < 80)
temp[2]++;
else if (score[i] >= 80 && score[i] < 90)
temp[3]++;
else if (score[i] >= 90 && score[i] < 100)
temp[4]++;
然后各分數段百分比:
temp[0] / 30 * 100
其它類推
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/45988.html
標籤:C語言
上一篇:我是萌新,求大佬幫忙
