100歲以上的判斷出錯(cuò),原因在于,你把100歲以上的人,仍然按10歲一級(jí)統(tǒng)計(jì)了(分別統(tǒng)計(jì)了110、120...以下),你的fun函數(shù)修改后(如果其他的地方?jīng)]有錯(cuò)的話):

創(chuàng)新互聯(lián)專(zhuān)注于濟(jì)寧企業(yè)網(wǎng)站建設(shè),自適應(yīng)網(wǎng)站建設(shè),成都做商城網(wǎng)站。濟(jì)寧網(wǎng)站建設(shè)公司,為濟(jì)寧等地區(qū)提供建站服務(wù)。全流程定制設(shè)計(jì),專(zhuān)業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)專(zhuān)業(yè)和態(tài)度為您提供的服務(wù)
void?fun(int?*a,?int?*b)
{
int?i,j,n;
for(j=0;jM;j++)
b[j]=0;?//計(jì)數(shù)器初始化
for(i=0;iN;i++)??//循環(huán)判斷所有的年齡
{
??n=a[i]/10;
??if(n10)
b[a[i]/10]++;
??else?b[10]++;
}
#include stdio.h
int main(void)
{
int num,A = 0,B = 0,C = 0,D = 0,E = 0,F = 0;
int i,score;
scanf("%d",num);
for(i = 0; i num; i++)
{
scanf("%d",score);
score /= 10;
switch(score)
{
case 9: A++;break;
case 8: B++;break;
case 7: C++;break;
case 6: D++;break;
default: E++;
}
}
printf("%d %d %d %d %d",A,B,C,D,E);
return 0;
}
湊個(gè)熱鬧
#include "stdio.h"
#include "malloc.h"
#include "string.h"
#define N 7
typedef struct node
{
char num[3]; /*教室的編號(hào)*/
char name[9]; /*教師的姓名*/
char sex[5]; /*教師的性別*/
char prof[6]; /*教師的職稱(chēng)*/
char dept[10]; /*教師所在院系*/
struct node * link;
}teacher;
void fun_count_prof( teacher *head )
{
teacher *p=head-link ;
char prof[6]="";
int cnt=0;
while (p)
{
if ( strcmp(prof,p-prof) )
{
if ( prof[0] )
printf("prof:%s cnt=%d\n" , prof , cnt );
//統(tǒng)計(jì)下一職稱(chēng)
cnt=0;
strcpy(prof,p-prof) ;
}
cnt++;
p=p-link ;
}
if ( prof[0] )
printf("prof:%s cnt=%d\n" , prof , cnt ) ;
}
void fun_count_dept_prof( teacher *head )
{
teacher *p=head-link ;
char prof[6]="";
char dept[10]="";
int cnt=0;
while (p)
{
//檢查職稱(chēng)變化
if ( strcmp(prof,p-prof) )
{
if ( prof[0] )
printf("dept:%s prof:%s cnt=%d\n" , dept , prof , cnt ) ;
//統(tǒng)計(jì)下一職稱(chēng)
cnt=0;
strcpy(dept,p-dept) ;
strcpy(prof,p-prof) ;
}
//檢查院系變化
if ( strcmp(dept,p-dept) )
{
//輸出上一院系的最后一個(gè)統(tǒng)計(jì)
printf("dept:%s prof:%s cnt=%d\n" , dept , prof , cnt ) ;
//統(tǒng)計(jì)下一院系
cnt=0;
strcpy(dept,p-dept) ;
}
cnt++;
p=p-link ;
}
if ( prof[0] )
printf("dept:%s prof:%s cnt=%d\n" , dept , prof , cnt ) ;
}
void crt_link( teacher *head )
{
//模擬數(shù)據(jù):要求數(shù)據(jù)按職稱(chēng)由高到低,職稱(chēng)下按部門(mén)排序,方便統(tǒng)計(jì)
struct teach_er
{
char num[3]; /*教室的編號(hào)*/
char name[9]; /*教師的姓名*/
char sex[5]; /*教師的性別*/
char prof[6]; /*教師的職稱(chēng)*/
char dept[10]; /*教師所在院系*/
} stTeacher[N]={
{"01","name0","male","prof0" , "mac"},
{"02","name1","male","prof0" , "com"},
{"03","name2","male","prof0" , "com"},
{"04","name3","male","prof1" , "mac"},
{"05","name4","male","prof1" , "mac"},
{"06","name5","male","prof1" , "com"},
{"07","name6","male","prof2" , "com"},
};
teacher *tail=head , *p ;
int i=0;
for ( i=0;iN;i++ )
{
p=malloc(sizeof(teacher) );
strcpy(p-num,stTeacher[i].num );
strcpy(p-name,stTeacher[i].name );
strcpy(p-sex,stTeacher[i].sex );
strcpy(p-prof,stTeacher[i].prof );
strcpy(p-dept,stTeacher[i].dept );
p-link=NULL ;
tail-link=p;
tail=p;
}
}
int main()
{
teacher *head;
head=malloc( sizeof(teacher) );
head-link=0;
crt_link( head );
fun_count_prof( head );
fun_count_dept_prof( head );
return 0;
}
#includestdio.hint 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("輸入錯(cuò)誤"); } for(i = 0; i 5; i++) { printf("%s%d\n",str[i],count[i]); } return 0;}
#include stdio.h //使用printf函數(shù)要包含的頭文件void main(void) //主函數(shù)
{
int n;
int x1=0,x2=0,x3=0,x4=0,x5=0;
printf("請(qǐng)輸入學(xué)生的成績(jī)1~100:\n");
scanf("%d",n);
while(n!=-1)
{
if(1=nn=59)
{
x1+=1;
}
else if(60=nn=69)
{
x2+=1;
}
else if(70=nn=79)
{
x3+=1;
}
else if(80=nn=89)
{
x4+=1;
}
else
{
x5=+1;
}
scanf("%d",n);
}
printf("1~59分?jǐn)?shù)段的人數(shù)為:%d\n",x1);
printf("60~69分?jǐn)?shù)段的人數(shù)為:%d\n",x2);
printf("70~79分?jǐn)?shù)段的人數(shù)為:%d\n",x3);
printf("80~89分?jǐn)?shù)段的人數(shù)為:%d\n",x4);
printf("90~100分?jǐn)?shù)段的人數(shù)為:%d\n",x5);
}
我說(shuō)說(shuō)思路
定義一個(gè)枚舉類(lèi)型保存職稱(chēng)
enum
{
Teaching_Assistant,?//助教
Lecturer,???????????//講師
Associate_Professor,//副教授
Professor???????????//教授
};
定義一個(gè)結(jié)構(gòu)體保存教師信息
typedef?struct?TeacherInfo
{
char?name[20];//保存教師姓名
int?TITLE;//保存職稱(chēng),在上面定義的enum中選取
}TI;
主函數(shù)中
#define?NUM?20????//教師人數(shù)
int?main(void)
{
TI?Teacher[NUM];//聲明20位老師信息
//輸入20位老師信息
//判斷教師職稱(chēng),統(tǒng)計(jì)信息
//輸出
return?0;
}
有了上面的思路,實(shí)現(xiàn)起來(lái)就很容易了
名稱(chēng)欄目:統(tǒng)計(jì)專(zhuān)業(yè)人數(shù)c語(yǔ)言函數(shù)題 統(tǒng)計(jì)次數(shù)c語(yǔ)言
網(wǎng)站路徑:http://chinadenli.net/article8/hpjgip.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計(jì)、網(wǎng)站導(dǎo)航、電子商務(wù)、、面包屑導(dǎo)航、網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)