printf(\ else
printf(\ } else
printf(\ return 0; }
int Strcmp(char *s,char *t) {
while (*s && *t && (*s == *t)) { s++; t++; }
return *s - *t; }
(6)
#include
static int a[M][N]; int i,j;
for( i = 0; i < M; i++ ) for( j = 0; j < N; j++ ) scanf( \ for( i = 0; i < M; i ++ )
printf(\ return 0; }
int sum (int *ptr) {
int i,result = 0;
for( i = 0; i < N; i++ ) result += *(ptr+i);
21
return result; } 6
第7章习题答案
1、选择题:
1-5 CCDBA 6-10 CBADB 11-13 DDA 2、 判断题
1-5 ×√√×√ 6-10 ×√×√√
第8章习题答案
1、选择题:
1-5 CDAAD 6-8 CDB 2、填空题
(1) .(成员域访问运算符),-〉(成员域间接访问运算符) (2) 4, 6.0 (3) enum (4) typedef
(5)
(2) p1->next, p1->next, p1->next 4、程序阅读题 (1) 7,3
(2)zhangping 20 (3) Li:3 Zhang:3 Wang:2 5.编程题
#include
#define N 10 /*学生人数 */ #define M 3 /* 课程数 */ struct stu{ /*定义结构体类型 */ char name[15]; char num[6]; float score[M]; float aver;
} student[N]; /*说明结构体变量 */
22
struct stu findmax(struct stu student[]); void input(struct stu student[]); void output(struct stu student[]); int main() {
struct stu temp; input(student); output(student);
temp = findmax(student); printf(\
printf(\ 1temp.score[0],temp.score[1],temp.score[2], temp.aver/M); system(\ return 0; }
struct stu findmax(struct stu student[]) {
float max = 0.0; int i,maxi;
for(i=0; i if(max < student[i].aver) { max = student[i].aver; maxi = i; } } return student[maxi]; } void input(struct stu student[]) { int i,j; printf(\ for( i=0;i scanf(\ student[i].aver = 0; for( j=0;j 23 { scanf(\ student[i].aver += student[i].score[j]; } } } void output(struct stu student[]) { int i,j; for( i=0;i printf(\ for( j=0;j printf(\ printf(\ } } 2 第9章 习题答案 1、选择题: 1-5 ADBBA 6-10 A CDAA 2、填空题 (1) 文本文件,二进制文件 (2) fopen, fclose (3) fprintf, fscanf, feof (4) fwrite, fread, fputs, fgets (5) 文本 , 二进制 (6) 1,0 (7) 字节,流式 3、程序填空题 (1) *fp1, *fp2, ftell(fp1); fgetc(fp1),fp2 (2)*fp, fp,sizeof(stud[0])*i,0 &stud[i] (3) “r”, fgetc(fp), count++ (4) FILE *f, sizeof(r), r.num,r.total 4、编程题 #include #define N 5 /*学生人数 */ #define M 3 /* 课程数 */ 24 struct stu{ /*定义结构体类型 */ char name[15]; char num[6]; float score[M]; float aver; } student[N]; /*说明结构体变量 */ void sort(struct stu student[]); void writetofile(struct stu student[], char filename[],char mode[]);int main() { FILE *fp; struct stu *ptr=NULL; int i,j; printf(\ for( i=0;i scanf(\ student[i].aver = 0; for( j=0;j scanf(\ student[i].aver += student[i].score[j]; 1 } } writetofile(student, \ writetofile(student, \ writetofile(student, \ sort(student); writetofile(student, \ ptr = (struct stu *)malloc(sizeof(struct stu)); scanf(\ ptr->aver = 0; for( j=0;j scanf(\ ptr->aver += ptr->score[j]; } if ((fp=fopen(\ { printf(\ 25