當前位置:首頁 » 編程軟體 » 一維數組編譯

一維數組編譯

發布時間: 2022-02-22 12:54:25

c語言一維數組

#include "stdio.h"
#define N 30
void main()
{
int grades[N]; //所有人的分數
int upAverage[N]; //超過平均分的學生序號
int unPass[N]; //不及格的學生序號
int nNum = 0; //學生總人數
int nUpAve = 0; //超過平均分的人數
int totGrade = 0; //總分
int n50,n60,n70,n80,n90; //各個分數段人數
double average; //平均分
int i;
//讀入成績
while (1){
scanf("%d",&grades[nNum]);
if (grades[nNum]<0) break;
totGrade += grades[nNum];
nNum++;
}
average = totGrade*1.0/nNum;
//統計各個分數段人數
n50 = n60 = n70 = n80 = n90 = 0;
for (i=0; i if (grades[i] >= average) upAverage[nUpAve++] = i;
if (grades[i] < 60) unPass[n50++] = i;
else if (grades[i] < 70) n60++;
else if (grades[i] < 80) n70++;
else if (grades[i] < 90) n80++;
else n90++;
}

//結果輸出
printf("不及格人數: %d\n",n50);
printf("不及格學生序號:");
for (i=0; i printf("\n成績在全班平均分及平均分之上的學生人數: %d\n",nUpAve);
printf("這些學生序號:");
for (i=0; i printf("\n以直方圖方式統計各分數段的學生人數及所佔的百分比\n");
printf("\n分數段 \t 學生人數\t圖形");
printf("\n <60 \t %2d(%.0lf%%) \t", n50, n50*100.0/nNum); for (i=0; i printf("\n 60-69 \t %2d(%.0lf%%) \t", n60, n60*100.0/nNum); for (i=0; i printf("\n 70-79 \t %2d(%.0lf%%) \t", n70, n70*100.0/nNum); for (i=0; i printf("\n 80-89 \t %2d(%.0lf%%) \t", n80, n80*100.0/nNum); for (i=0; i printf("\n >=90 \t %2d(%.0lf%%) \t", n90, n90*100.0/nNum); for (i=0; i printf("\n");
}

熱點內容
app什麼情況下找不到伺服器 發布:2025-05-12 15:46:25 瀏覽:714
php跳過if 發布:2025-05-12 15:34:29 瀏覽:467
不定時演算法 發布:2025-05-12 15:30:16 瀏覽:131
c語言延時1ms程序 發布:2025-05-12 15:01:30 瀏覽:166
動物園靈長類動物配置什麼植物 發布:2025-05-12 14:49:59 瀏覽:737
wifi密碼設置什麼好 發布:2025-05-12 14:49:17 瀏覽:149
三位數乘兩位數速演算法 發布:2025-05-12 13:05:48 瀏覽:399
暴風影音緩存在哪裡 發布:2025-05-12 12:42:03 瀏覽:544
access資料庫exe 發布:2025-05-12 12:39:04 瀏覽:632
五開的配置是什麼 發布:2025-05-12 12:36:37 瀏覽:366