好文档 - 专业文书写作范文服务资料分享网站

《C语言程序设计》课后习题答案(第四版)谭浩强23019

天下 分享 时间: 加入收藏 我要投稿 点赞

return(sum); }

9-2-2

#include struct y_m_d {int year; int month; int day; } date; int main()

{ int days(int year,int month,int day); int days(int,int,int); int day_sum;

printf(\

scanf(\ day_sum=days(date.year,date.month,date.day);

printf(\}

int days(int year,int month,int day) {int day_sum,i;

int day_tab[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; day_sum=0;

for (i=1;i

if ((year%4==0 && year0!=0 || year%4==0) && month>=3) day_sum+=1; return(day_sum); } 9-3

#include #define N 5

struct student { char num[6]; char name[8]; int score[4]; }stu[N];

int main()

{void print(struct student stu[6]); int i,j;

for (i=0;i

{printf(\ printf(\

scanf(\ printf(\

scanf(\ for (j=0;j<3;j++)

{printf(\

scanf(\ }

printf(\}

print(stu); return 0; }

void print(struct student stu[6]) {int i,j;

printf(\ NO. name score1 score2 for (i=0;i

{printf(\ for (j=0;j<3;j++)

printf(\ printf(\ } } 9-4

#include #define N 5

struct student {char num[6]; char name[8]; int score[4]; } stu[N];

int main()

{void input(struct student stu[]); void print(struct student stu[]); input(stu);

score3\\n\ print(stu); return 0; }

void input(struct student stu[]) {int i,j;

for (i=0;i

{printf(\ printf(\

scanf(\ printf(\ \

scanf(\ for (j=0;j<3;j++)

{printf(\

scanf(\ }

printf(\ } }

void print(struct student stu[6]) {int i,j;

printf(\ NO. name score1 score2 \\n\

for (i=0;i

{printf(\ for (j=0;j<3;j++)

printf(\ printf(\ } 9-5

#include #define N 10 struct student { char num[6]; char name[8]; float score[3]; float avr; } stu[N];

int main()

score3

{ int i,j,maxi;

float sum,max,average; for (i=0;i

{printf(\ printf(\

scanf(\ printf(\

scanf(\ for (j=0;j<3;j++)

{printf(\ scanf(\ } }

average=0; max=0; maxi=0;

for (i=0;i

for (j=0;j<3;j++)

sum+=stu[i].score[j]; stu[i].avr=sum/3.0; average+=stu[i].avr; if (sum>max) {max=sum; maxi=i; } }

average/=N;

printf(\ NO. name score1 score2 score3 average\\n\ for (i=0;i

{printf(\ for (j=0;j<3;j++)

printf(\ printf(\ %8.2f\\n\ }

printf(\

printf(\ printf(\ stu[maxi].score[0],stu[maxi].score[1],stu[maxi].score[2],stu[maxi].avr); return 0; }

9-6

#include #define N 13

struct person {int number; int nextp; } link[N+1];

int main()

{int i,count,h;

for (i=1;i<=N;i++) {if (i==N)

link[i].nextp=1; else

link[i].nextp=i+1; link[i].number=i; }

printf(\ count=0; h=N;

printf(\ while(count

while(i!=3)

{h=link[h].nextp; if (link[h].number) i++; }

printf(\ link[h].number=0; count++; }

printf(\ for (i=1;i<=N;i++) if (link[i].number)

printf(\ printf(\ return 0; } 9-7

#include

《C语言程序设计》课后习题答案(第四版)谭浩强23019

return(sum);}9-2-2#includestructy_m_d{intyear;intmonth;intday;}date;intmain(){intdays(intyear,intmonth,intday);i
推荐度:
点击下载文档文档为doc格式
87azb13lxw6x2111f20r4n7xz5ee5l00bm8
领取福利

微信扫码领取福利

微信扫码分享