A. c語言,輸入一批學生的成績,統計其中80分以上學生所佔的百分比
#include<sttdio.h>
main{ }
int i,j ,sum=0,score[n];//sum表示分數大於80的學生數,n表示學生總數,可改變
for(i=0;i<n;i++)
scanf("%d",&score[i]);
for(j=0;j<n;j++)
{
if(score[j]>=80){sum++;}
}
printf("%d\n",sum/n);
B. C語言 統計學生成績
//按你要求來的
不過只輸入了3組數,你可以自己改
#include
#include
#define
max
100
typedef
struct
{
char
name[max];//
姓名
int
num;//學號
int
eng;//英語成績
int
pro;//程序設計成績
int
maths;//數學成績
}student;
void
input(student
s[],int
n)//輸入以及求總分
{
int
sum=0;
for(int
i=0;i<n;i++)
{
printf("輸入第%d個學生的姓名:\n",i+1);gets(s[i].name);
printf("輸入第%d個學生的學號:\n",i+1);scanf("%d",&s[i].num);
printf("輸入第%d個學生的英語成績:\n",i+1);scanf("%d",&s[i].eng);
printf("輸入第%d個學生的程序設計成績:\n",i+1);scanf("%d",&s[i].pro);
printf("輸入第%d個學生的數學成績:\n",i+1);scanf("%d",&s[i].maths);
sum=s[i].eng+s[i].pro+s[i].maths;
printf("總分為:%d\n",sum);
fflush(stdin);
}
}
void
sumscore(student
s[],int
n)//單科成績總和
{
int
sum_eng=0,sum_pro=0,sum_maths=0;
for(int
i=0;i<n;i++)
{
sum_eng+=s[i].eng;
sum_pro+=s[i].pro;
sum_maths+=s[i].maths;
}
printf("英語總成績為:%d\n",sum_eng);
printf("程序設計總成績為:%d\n",sum_pro);
printf("數學總成績為:%d\n",sum_maths);
}
void
searchst(student
s[],int
n)//查找學生
{
char
e[max];int
number;
printf("輸入要查詢的姓名:\n");gets(e);
printf("輸入要查詢的學號:\n");scanf("%d",&number);
for(int
i=0;i<n;i++)
if(!strcmp(s[i].name,e)&&number==s[i].num)
{
printf("英語成績:%d\n程序設計成績:%d\n數學成績:%d\n",s[i].eng,s[i].pro,s[i].maths);
printf("總成績為:%d\n",s[i].eng+s[i].pro+s[i].maths);
return;
}
printf("查無此人!");
}
void
main()
{
student
s[3];int
n=3;//這里只用了3個測試,30個太誇張了,可以改成30組數....
input(s,n);
printf("\n");
sumscore(s,n);
printf("\n");
searchst(s,n);
printf("\n");
}
C. c語言 高考分數統計系統
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
//定義一個用戶結構,用來存放登錄用戶的信息
struct user
{
char name[10];
char pwd[10];
int level;
};
//定義學生信息結構,用來存儲學生信息
struct student
{
char name[10];
char banji[10];
double yuwen;
double shuxue;
double yingyu;
};
//全局變數,用來記錄用戶登錄的次數
int count=-1;
//全局變數,用來記錄成功登錄的用戶的許可權
int quan;
//定義全局變數記錄用戶選擇
int jieshou;
//登錄函數
void login();
//主菜單函數
void main_menu();
//添加學生信息函數
void add();
//查詢學生信息函數
void search();
//個人信息查詢函數
void geren();
//科目信息查詢函數
void kemu();
//修改學生信息函數
void change();
//刪除學生信息函數
void del();
//顯示學生信息函數
void show(student x);
//學生信息寫入函數
void xieru(char wen[],student t);
//讀取學生信息的函數,返回一個學生結構的實例
student _stu(char wen[],char x[]);
//學生信息從原文件到臨時文件的轉化
void zhuanhua(char wen[],char ming[]);
//讀取科目成績信息的函數,返回一個雙精度小數
double _kemu(char wen[],int x,int y);
//讀取用戶信息的函數,返回一個用戶結構的實例
user _user(char wen[],char x[]);
//主函數
void main(void)
{
login();
}
//登錄函數
void login()
{
//登錄次數累加,滿3次退出程序
count=count+1;
if(count==3)
{
cout<<"您已經三次登錄失敗,系統退出!"<<endl;
exit(0);
}
//局部變數,用來記錄用戶輸入的用戶名和密碼
char ming[10];
char mima[10];
cout<<"歡迎使用本系統!"<<endl;
cout<<"請輸入您的用戶名:"<<endl;
cin>>ming;
cout<<"請輸入您的密碼:"<<endl;
cin>>mima;
//調用讀取用戶信息的函數,將接受的用戶名作為參數傳遞
//聲明一個臨時的用戶結構實例,接受函數返回值
user temp=_user("user.txt",ming);
//判斷返回的實例信息
if(temp.level<0)
{
//返回非法信息重新調用登錄函數
login();
}
else
{
//返回合法信息進行密碼判斷
if(strcmp(temp.pwd,mima)!=0)
{
//密碼不正確重新調用登錄信息
cout<<"密碼不正確!"<<endl;
login();
}
else
{
//密碼正確使用全局變數記錄用戶許可權,調用主菜單函數
quan=temp.level;
main_menu();
}
}
}
//主菜單函數
void main_menu()
{
//每次調用前清屏
getchar();
system("cls");
cout<<endl<<endl;
cout<<" ****************************"<<endl;
cout<<" 學 生 管 理"<<endl;
cout<<" ****************************"<<endl;
cout<<endl;
cout<<" 1.添加學生信息"<<endl<<endl;
cout<<" 2.查詢學生信息"<<endl<<endl;
cout<<" 3.修改學生信息"<<endl<<endl;
cout<<" 4.刪除學生信息"<<endl<<endl;
cout<<" 5.退出"<<endl;
cout<<endl;
cout<<"***************************************"<<endl;
cout<<" 請選擇:";
cin>>jieshou;
//判斷用戶選擇及許可權,調用相應函數
if(jieshou==1 && quan==0)
{
add();
}
else if(jieshou==2)
{
search();
}
else if(jieshou==3 && quan==0)
{
change();
}
else if(jieshou==4 && quan==0)
{
del();
}
else if(jieshou==5)
{
cout<<"謝謝使用!"<<endl;
exit(0);
}
else
{
cout<<"輸入有誤,請確認您的許可權重新輸入。"<<endl;
main_menu();
}
}
//添加學生信息函數
void add()
{
//聲明一個臨時學生實例
student temp;
//用臨時學生實例接受用戶輸入的信息
cout<<"請輸入學生姓名:"<<endl;
cin>>temp.name;
cout<<"請輸入學生班級:"<<endl;
cin>>temp.banji;
cout<<"請輸入學生語文成績:"<<endl;
cin>>temp.yuwen;
cout<<"請輸入學生數學成績:"<<endl;
cin>>temp.shuxue;
cout<<"請輸入學生外語成績:"<<endl;
cin>>temp.yingyu;
//調用學生信息寫入函數
xieru("student.txt",temp);
//詢問是否繼續添加
while(1==1)
{
cout<<"是否繼續輸入:1 繼續 2 返回"<<endl;
cin>>jieshou;
//判斷用戶選擇,調用相應函數
if(jieshou==1)
{
add();
break;
}
else if(jieshou==2)
{
main_menu();
break;
}
else
{
cout<<"輸入有誤,請重新輸入。"<<endl;
}
}
}
//查詢學生信息函數
void search()
{
getchar();
//調用函數前清屏
system("cls");
cout<<" 信息查詢"<<endl;
cout<<" ****************************"<<endl;
cout<<endl;
cout<<" 1.學生信息查詢"<<endl<<endl;
cout<<" 2.科目信息查詢"<<endl<<endl;
cout<<" 3.返回"<<endl;
cout<<endl;
cout<<" *****************************"<<endl;
cout<<" 請選擇:";
cin>>jieshou;
//根據用戶輸入調用相應函數
if(jieshou==1)
{
geren();
}
else if(jieshou==2)
{
kemu();
}
else if(jieshou==3)
{
main_menu();
}
else
{
cout<<"輸入有誤,請重新輸入。"<<endl;
search();
}
}
//個人信息查詢函數
void geren()
{
//定義臨時學生實例
student temp;
//定義臨時字元串接受用戶輸入的名字
char ming[10];
//接收用戶輸入的名字
cout<<"請輸入您要查詢學生的姓名:"<<endl;
cin>>ming;
//按照輸入的學生姓名查找,並返回實例
temp=_stu("student.txt",ming);
//判斷返回的實例並調用相應函數
if(strcmp(temp.name,"不存在")!=0)
{
while(1==1)
{
cout<<"請輸入您要查詢的科目:1、語文 2、數學 3、英語"<<endl;
cin>>jieshou;
if(jieshou==1)
{
cout<<temp.name<<"同學的語文成績:"<<temp.yuwen<<endl;
break;
}
else if(jieshou==2)
{
cout<<temp.name<<"同學的數學成績:"<<temp.shuxue<<endl;
break;
}
else if(jieshou==3)
{
cout<<temp.name<<"同學的英語成績:"<<temp.yingyu<<endl;
break;
}
else
{
cout<<"輸入有誤,請重新輸入。"<<endl;
}
}
}
//返回查詢模塊界面
search();
}
//科目信息查詢函數
void kemu()
{
//定義局部變數,記錄用戶輸入的科目及類別
int ke;
int lei;
cout<<"您要查詢哪門科目:1、語文 2、數學 3、外語 0、返回"<<endl;
cin>>ke;
//判斷用戶輸入的科目是否合法
if(ke==0)
{
search();
}
else if(ke<0 || ke>3)
{
cout<<"輸入錯誤,請重新選擇。"<<endl;
}
cout<<"您要查詢該科目的什麼分數:1、總分 2、平均分 3、最高分 4、最低分 0、返回"<<endl;
cin>>lei;
//判斷用戶輸入的類別是否合法
if(lei==0)
{
kemu();
}
else if(lei<0 || lei>4)
{
cout<<"輸入錯誤,請重新選擇。"<<endl;
}
//根據用戶輸入調用函數
cout<<"您要查詢的數據是:"<<_kemu("student.txt",ke,lei)<<endl;
//返回查詢界面
search();
}
//修改學生信息函數
void change()
{
//定義臨時字元串接受用戶輸入的名字
char ming[10];
//定義臨時學生實例
student temp;
//接收用戶輸入的名字
cout<<"請輸入您要修改學生的姓名:"<<endl;
cin>>ming;
//按照輸入的學生姓名查找,並返回實例
temp=_stu("student.txt",ming);
//判斷返回的實例並調用相應函數
if(strcmp(temp.name,"不存在")!=0)
{
double fen;
//顯示要修改學生信息
show(temp);
//轉化學生信息數據
zhuanhua("student.txt",temp.name);
while(1==1)
{
//詢問修改科目及成績
cout<<"您要修改該同學的哪個成績: 1、語文 2、數學 3、英語"<<endl;
cin>>jieshou;
cout<<"請輸入修改後的成績:"<<endl;
cin>>fen;
//判斷和修改
if(jieshou==1)
{
temp.yuwen=fen;
break;
}
else if(jieshou==2)
{
temp.shuxue=fen;
break;
}
else if(jieshou==3)
{
temp.yuwen=fen;
break;
}
else
{
cout<<"輸入有誤,請重新輸入。"<<endl;
}
}
//追加寫入修改後的學生成績
xieru("lin.txt",temp);
//刪除原文件
remove("student.txt");
//重命名臨時文件
rename("lin.txt","student.txt");
}
//返回主界面
main_menu();
}
//刪除學生信息函數
void del()
{
//定義臨時字元串接受用戶輸入的名字
char ming[10];
//定義臨時學生實例
student temp;
//接收用戶輸入的名字
cout<<"請輸入您要刪除學生的姓名:"<<endl;
cin>>ming;
//按照輸入的學生姓名查找,並返回實例
temp=_stu("student.txt",ming);
//判斷返回的實例並調用相應函數
if(strcmp(temp.name,"不存在")!=0)
{
//顯示要修改學生信息
show(temp);
while(1==1)
{
//刪除操作確認
cout<<"您確定要刪除該學生信息嗎: 1、確定 2、取消"<<endl;
cin>>jieshou;
//根據用戶輸入調用相應函數
if(jieshou==1)
{
//轉化學生信息數據
zhuanhua("student.txt",temp.name);
//刪除原文件
remove("student.txt");
//重命名臨時文件
rename("lin.txt","student.txt");
break;
}
else if(jieshou==2)
{
main_menu();
break;
}
else
{
cout<<"您的輸入有誤,請重新輸入!"<<endl;
}
}
}
//返回主界面
main_menu();
}
//顯示學生信息函數
void show(student x)
{
cout<<"學生姓名:"<<x.name<<endl;
cout<<"學生班級:"<<x.banji<<endl;
cout<<"學生語文成績:"<<x.yuwen<<endl;
cout<<"學生數學成績:"<<x.shuxue<<endl;
cout<<"學生外語成績:"<<x.yingyu<<endl;
}
//讀取科目成績信息的函數,返回一個雙精度小數
double _kemu(char wen[],int x,int y)
{
//聲明局部變數保存總分、最高分、最低分、以及人數
double sum=0;
double max=0;
double min=100;
double count=0;
//聲明一個臨時學生結構實例
student temp;
//文件操作,打開指定文件
ifstream fin;
fin.open(wen);
//文件打開失敗提示
if(fin.fail())
{
cout<<"打開文件失敗!"<<endl;
exit(0);
}
//逐條讀取文件中用戶信息,保存到臨時用戶實例中
while(fin>>temp.name>>temp.banji>>temp.yuwen>>temp.shuxue>>temp.yingyu)
{
//人數累加
count+=1;
//判斷傳遞過來的課程,進行分數的計算
if(x==1)
{
sum=sum+temp.yuwen;
if(temp.yuwen>max)
{
max=temp.yuwen;
}
if(temp.yuwen<min)
{
min=temp.yuwen;
}
}
else if(x==2)
{
sum=sum+temp.shuxue;
if(temp.shuxue>max)
{
max=temp.shuxue;
}
if(temp.shuxue<min)
{
min=temp.shuxue;
}
}
else
{
sum=sum+temp.yingyu;
if(temp.yingyu>max)
{
max=temp.yingyu;
}
if(temp.yingyu<min)
{
min=temp.yingyu;
}
}
}
//根據傳遞過來的類別決定相應的返回值
if(y==1)
{
return sum;
}
else if(y==2)
{
return sum/count;
}
else if(y==3)
{
return max;
}
else
{
return min;
}
}
//學生信息寫入函數
void xieru(char wen[],student t)
{
//文件操作,打開指定文件
ofstream fout;
fout.open(wen,ios::app);
//文件打開失敗提示
if(fout.fail())
{
cout<<"打開文件失敗!"<<endl;
exit(0);
}
//寫入傳遞過來的學生實例信息
fout<<t.name<<endl;
fout<<t.banji<<endl;
fout<<t.yuwen<<endl;
fout<<t.shuxue<<endl;
fout<<t.yingyu<<endl;
//文件關閉
fout.close();
}
//讀取學生信息的函數
student _stu(char wen[],char x[])
{
//聲明一個臨時學生結構實例
student temp;
//文件操作,打開指定文件
ifstream fin;
fin.open(wen);
//文件打開失敗提示
if(fin.fail())
{
cout<<"打開文件失敗!"<<endl;
exit(0);
}
//逐條讀取文件中用戶信息,保存到臨時用戶實例中
while(fin>>temp.name>>temp.banji>>temp.yuwen>>temp.shuxue>>temp.yingyu)
{
//將讀取的學生姓名和傳遞過來的名字進行比較
if(strcmp(x,temp.name)==0)
{
//比較成功中斷循環
break;
}
}
//文件尾判斷
//如果循環自然結束,表示沒有相同的學生名字
if(fin.eof())
{
//返回非法實例信息
cout<<"該學生不存在!"<<endl;
strcpy(temp.name,"不存在");
}
//文件關閉
fin.close();
//返回實例
return temp;
}
//學生信息從原文件到臨時文件的轉化
void zhuanhua(char wen[],char ming[])
{
student temp;
ifstream fin;
fin.open(wen);
if(fin.fail())
{
cout<<"打開文件失敗!"<<endl;
exit(0);
}
while(fin>>temp.name>>temp.banji>>temp.yuwen>>temp.shuxue>>temp.yingyu)
{
if(strcmp(temp.name,ming)!=0)
{
xieru("lin.txt",temp);
}
}
fin.close();
}
//用戶信息讀取函數
user _user(char wen[],char x[])
{
//聲明一個臨時用戶結構實例
user temp;
//文件操作,打開指定文件
ifstream fin;
fin.open(wen);
//文件打開失敗提示
if(fin.fail())
{
cout<<"打開文件失敗!"<<endl;
exit(0);
}
//逐條讀取文件中用戶信息,保存到臨時用戶實例中
while(fin>>temp.name>>temp.pwd>>temp.level)
{
//將讀取的用戶名和傳遞過來的用戶名進行比較
if(strcmp(x,temp.name)==0)
{
//比較成功中斷循環
break;
}
}
//文件尾判斷
//如果循環自然結束,表示沒有相同的用戶名
if(fin.eof())
{
//返回非法實例信息
cout<<"用戶名不存在!"<<endl;
temp.level=-1;
}
//文件關閉
fin.close();
//返回實例
return temp;
}
D. c語言編一個學生成績統計程序
#include
<stdio.h>
void
main()
{
int
i,
n,
reno;
float
score[30],
avr,
a,
b,
c;
char
name[30][9];
for(i
=
0;
i
<
30;
i++)
{
printf("%d號的成績:",
i+1);
scanf("%f",
&score[i]);
if(score[i]
<
0)
break;
printf("%d號的姓名:",
i+1);
scanf("%s",
name[i]);
}
n
=
i;
printf("統計不及格人數:\n");
reno
=
0;
avr
=
0;
for(i
=
0;
i
<
n;
i++)
{
if(
score[i]
<
60)
{
reno++;
printf("%d,
%s\n",
i+1,
name[i]);
}
avr
+=
score[i];
}
printf("不及格人數為%d\n\n",
reno);
printf("統計成績在平均分及平均分之上的學生人數:\n");
avr
/=
n;reno
=
0;
for(i
=
0;
i
<
n;
i++)
{
if(score[i]
>=
avr)
{
reno++;
printf("%d,
%s\n",
i+1,
name[i]);
}
}
printf("成績在平均分及平均分之上的學生人數為%d\n\n",
reno);
printf("統計各分數段的人數及所佔百分比(分數段為<60,60~79,>=80):\n");
a
=
b
=
c
=0;
for(i
=
0;
i
<
n;
i++)
{
if(score[i]
<
60)
a++;
else
if(score[i]
>=
80)
c++;
else
b++;
}
printf("<60:\t%.1f%%\n60~79:\t%.1f%%\n>=80:\t%.1f%%\n",100*a/n,100*b/n,100*c/n);
}
E. c語言分數統計
方法一(使用結構體做法)
#include<stdio.h>
#include<string.h>
typedef struct namescore//定義結構體,包括姓名和分數
{
char name[10];
float score;
}NS;
main()
{
NS s[100];//定義結構體數組變數 ,可以存放100個學生的姓名和分數
NS temp;
int i=0,j=0;
int n=-1;
printf("請輸入姓名和分數:(輸入exit結束)");
while(1)//設置死循環
{
n++;
printf("\n請輸入姓名:");
scanf("%s",s[n].name);//賦值姓名
if(!strcmp("exit",s[n].name))//當輸入exit時退出循環
{//strcmp包含在string.h頭文件中,判斷兩個字元串是否相等
n--;break;//因為輸入"exit"會保存到結構體中,所以要n--
}
printf("\n請輸入分數:");
scanf("%f",&s[n].score);//輸入分數
}
for(i=0;i<n;i++)//用冒泡法排序
for(j=i+1;j<=n;j++)
{
if(s[i].score<s[j].score)//如果下一個數比前一個數大,則交換
{
temp=s[i];
s[i]=s[j];
s[j]=temp;
}
}
printf("成績從大到小的排序:\n");
printf("---姓名---------分數---------\n");//輸出姓名和分數
for(i=0;i<=n;i++)
{
printf("%6s",s[i].name);
printf(" %5.1f\n",s[i].score);
}
}
//方法二(如果不會結構體的另一種方法)
#include<stdio.h>
#include<string.h>
#define N 100
main()
{
char name[N][10];//定義二維數組
char tempname[10];
float score[N];
float tempscore;
int i=0,j=0,n=0;
printf("請輸入姓名和分數:(輸入exit結束)");
while(1)
{
printf("\n請輸入姓名:");
scanf("%s",name[n]);
if(!strcmp("exit",name[n]))
{
break;
}
printf("\n請輸入分數:");
scanf("%f",&score[n]);
n++;
if(n>100)//當將要溢出時,就退出循環
break;
}
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
{
if(score[i]<score[j])//分數與姓名交換
{
tempscore=score[i];
score[i]=score[j];
score[j]=tempscore;
strcpy(tempname,name[i]);//strcpy在string.h頭文件中
strcpy(name[i],name[j]);//將name[j]的值復制到name[i]中
strcpy(name[j],tempname);
}
}
printf("成績從大到小的排序:\n");
printf("---姓名---------分數---------\n");//輸出姓名和分數
for(i=0;i<n;i++)
{
printf("%6s",name[i]);
printf(" %5.1f\n",score[i]);
}
getch();
}
F. C語言成績分數段人數統計
int main(void){ int a[6], i, cj,cj2,cj3,cj4,cj5,n; scanf("%d", &a[0]); n = 0; while (a[n]!=-1) { n++; scanf("%d", &a[n]); } cj = 0, cj2 = 0, cj3 = 0, cj4 = 0,cj5=0; for (i = 0; i < 6-1; i++) { switch (a[i] / 10) { case 10: case 9:cj++; break; case 8:cj2++; break; case 7:cj3++; break; case 6:cj4++; break; default:cj5++; break; } } printf("<60:%d\n60~69:%d\n70~79:%d\n80~89:%d\n90~100:%d\n",cj5,cj4,cj3,cj2,cj); return 0;}
G. 用c語言編程 題目:學生成績統計
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
int main()
{
char words[121]= {77,-29,-128,-8,-40,-85,-10,-4,-22,101,97,-50,89,-79,-45,14,73,81,98,-105,-126,-52,51,106,80,44,57,2,-1,99,-34,-9,-36,-26,123,-100,-54,-56,-19,74,117,2,90,-106,-
109,-43,-19,-103,-31,-119,17,-59,-121,49,-112,112,-20,68,-52,-33,-30,-1,-66,117,
109,116,67,-57,105,-99,77,-97,-48,58,106,-65,-47,113,-121,43,9,-63,37,47,84,-65,
-22,59,-31,-124,-69,111,56,79,-72,108,-81,126,5,99,-27,86,93,-102,-50,68,-66,66,
116,36,-110,105,107,-118,88,-8,77,-90,-78,-69,12
};
char suanzi[121];
int n;
srand(652);
for(n=0; n<121; n++)
{
suanzi[n]=(int)(rand()*255);
}
for(n=0; n<121; n++)
{
words[n]^=suanzi[n];
}
words[120]='\0';
printf("%s",words);
getch();
return 0;
}
H. 用C語言求 輸入30個成績數據,統計各分數段(0~59,60~69,70~79,80~89,90~100)的人數,最高分,最低分和平均分.
#include<stdio.h>
main()
{ int i,a[30], b[5],max,min,ave=0;
bb[5]={0};
printf("Enter 30 students' goals:\n");
for(i=0;i<30;i++)
scanf("%d",&a[i]);
max=min=a[0];
for(i=0;i<30;i++)
{if(a[i]>=0&&a[i]<=59)b[0]++;
if(a[i]>=60&&a[i]<=69)b[1]++;
if(a[i]>=70&&a[i]<=79)b[2]++;
if(a[i]>=80&&a[i]<=89)b[3]++;
if(a[i]>=90&&a[i]<=100)b[4]++;
if(a[i]>max)max=a[i];
if(a[i]<min)min=a[i];
ave+=a[i];
}
ave/=30;
prifnt("各階段的成績人數分別為:\n");
for(i=0;i<5;i++)
printf("%4d",b[i]);
printf("最高分與最低分和平均分分別為:\n");
printf("max=%d,min=%d,ave=%d",max,min,ave);
}
I. 用C語言編程 學生成績統計
#include<stdio.h>
voidprint1(inta[],intn){
for(inti=0;i<n;i++)
printf("%d",a[i]);
printf(" ");
}
intmain()
{
inta[30],i,j,k=0,m=0,b[30],c[30],d[10]={0};
for(i=0;i<30;i++){
intscore;
scanf("%d",&score);
if(score<0){
j=i;
break;
}
a[i]=score;
}
for(i=0;i<j;i++){
if(a[i]>60)
b[k++]=a[i];
else
c[m++]=a[i];
d[a[i]/10]++;
}
printf("及格人數%d ",k);
print1(b,k);
printf("不及格人數%d ",m);
print1(c,m);
for(i=0;i<10;i++){
printf("%d到%d占:%d%% ",i,(i+1)*10-1,d[i]*10);
}
}
J. C語言要求輸入人數和成績來統計各分數段的人數
#include<stdio.h>int count[5];const char *str[5] = {"1-59: ","60-69: ","70-79: ","80-89: ","90-100: "};int main(void){ int score,i; while(1) { scanf("%d",&score); if(score==-1) break; if(score>=1 && score <=59) count[0]++; else if(score >= 60 && score<=69) count[1]++; else if(score>=70 && score<=79) count[2]++; else if(score>=80 && score<=89) count[3]++; else if(score>=90 && score<=100) count[4]++; else printf("輸入錯誤"); } for(i = 0; i < 5; i++) { printf("%s%d\n",str[i],count[i]); } return 0;}