C语言程序设计 (江宝钏 著) 清华大学出版社 第9章习题答案1
一、程序阅读题 习题 9 答案 1.B2. C 二、编程题 1. #include #defineM 10 structstudent { intstu_id; 3. D 4. C }; charstu_name[8]; structdate { intyear; intmonth; }birthday; floatstu_course[3]; floatstu_avg; voidmain() { inti; structstudent p[M]; for(i=0;isalary=1.05*(pwork->salary); pwork->income=pwork->salary+pwork->bonus-pwork->deduction; } for(i=0;iname,pwork->salary,pwork->bonus,pwork->deduction, pwork->income); } } 3. #include intmain() {charop; doublea1,a2,b1,b2; intnumber; number=2;//run the program for third time do {printf(“please a1,a2,b1,b2 and opteration \n“); scanf(“%lf,%lf,%c,%lf,%lf“, switch(op) {case + : printf(“(%lf+%lfi)+(%lf+%lfi)=%lf+%lfi“,a1,a2,b1,b2,a1+b1,a2+b2); case - : printf(“\n“); break; printf(“(%lf+%lfi)-(%lf+%lfi)=%lf+%lfi“,a1,a2,b1,b2,a1-b1,a2-b2); printf(“\n“); break; case * : printf(“(%lf+%lfi)*(%lf+%lfi)=%lf+%lfi“,a1,a2,b1,b2,a1*b1-a2*b2,a1*b2+a2*b1); printf(“\n“); break; default: printf(“error\n“); } }while(number--); return0; } 4. #include“stdio.h“ structCandidate//define the Candidate struct {intId; charName[6] ; intBallot_Num; }; //define the global variableand initaliz the four candidates structCandidate Total[4]={ {1,“wang“,0}, {2,“liu“,0}, {3,“li“,0}, {4,“zhou“,0} }; //function for display the Candidates names voidPrintName(chara[]){ char*p; p=a; while((*p >= a p++; } } //function for display the Candidates inforamtion voidprint_Candi_inf(Candidate Total[]) { printf(“Can_ID,Can_name,Ballot_Num\n“); intj; for(j=0;j<4;j++) { printf(“***********************\n“); printf(“%d“,Total[j].Id); printf(“ “); PrintName(Total[j].Name); printf(“ “); } printf(“%d“,Total[j].Ballot_Num); printf(“\n“); } // function for count the candidate s ballot voidVote(intt) {inti; for(i=0;i0); return0; }