第7章C语言程序设计习题答案

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
{pa2=pa1;
pa1=pa1->next;
}
if(pb1->num<=pa1->num)
{if(ah==pa1)
ah=pb1;
else
pa2->next=pb1;
pb1=pb1->next;
pb2->next=pa1;
pa2=pb2;
pb2=pb1;
}
}while((pa1->next!=NULL)||(pa1==NULL&&pb1!=NULL));
if((pb1->num>pa1->num)&&(pa1->next==NULL))
pa1->next=pb1;
return(ah);
}
void print(struct student *head)
{struct student *p;
printf("\n共有%d条记录,它们是:\n",sum);
sum=sum+n;
abh=insert(ahead,bhead);
print(abh);
}
二、选择题
1.D2.C3.B4.C5.B6.B7.B8.B9.A10.C
11.D12.B13.A14.D15.C16.A17.C18.C
三、填空题
1.【1】struct list *【2】q
2.【1】struct link *next
return(head);
}
struct student *insert(struct student *ah, struct student *bh)
{struct student *pa1,*pa2,*pb1,*pb2;
pa2=pa1=ah;
pb2=pb1=bh;
do
{while((pb1->num>pa1->num)&&(pa1->num!=NULL))
p=head;
if(p!=NULL)
do
{printf("%d,%d\n",p->num,p->score);
p=p->next;}while(p!=NULL);
}
main()
{struct student *ahead,*bhead,*abh;
ahead=creat();
sum=n;
bhead=creat();
head=NULL;
while(p1->num!=0)
{n++;
if(n==1)Biblioteka Baidu
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct student *)malloc(LEN);
scanf("%d,%d",&p1->num,&p1->score);
}
p2->next=NULL;
int n,sum=0;
struct student *creat()
{struct student *p1,*p2,*head;
n=0;
p1=p2=(struct student *)malloc(LEN);
printf("请输入学生的学号和成绩(学号为0则停止输入):\n");
scanf("%d,%d",&p1->num,&p1->score);
}
7.
#include "stdio.h"
struct d
{int year;
int month;
int day;}date;
int days(int year,int month,int day)
{int totalday=0,i;
static int day_tab[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
}
8.
#include "stdio.h"
#include "malloc.h"
#define NULL 0
#define LEN sizeof(struct student)
struct student
{long num;
int score;
struct student *next;}lista,liatb;
for(i=1;i<month;i++)
totalday+=day_tab[i];
totalday+=day;
if((year%4==0&&year%100!=0||year%400==0)&&month>3)
totalday+=1;
return(totalday);
}
main( )
{int totalday;
{int i,j;
char name[20];
for(i=1;i<=20;i++)
{scanf(“%s”,name);
for(j=0;j<5;j++)
if (strcmp(name,leader[j].name)==0) leader[j].count++;
}
for(i=0;i<5;i++)
printf(“%20s:%d\n”,leader[i].name,leader[i].count);
printf("请输入年、月、日:");
scanf("%d,%d,%d",&date.year,&date.month,&date.day);
totalday=days(date.year,date.month,date.day);
printf("\n%d月%d日是%d年的第%d天\n",date.month,date.day,date.year,totalday);
3.【1】34
4.【1】struct STRU *
5.【1】struct st或ex
6.【1】char *data【2】struct link *next

习题七
一、思考题
6.
#include “stdio.h”
#include “string.h”
struct person
{char name[20];
int count;}leader[5]={“li”,0, “wang”,0, “liu”,0, “zhao”,0, “zhang”,0};
main()
相关文档
最新文档