算并输出每个人的学号和平均成绩。
2.已知链表结点结构如下,假设动态链表已经建立,请编写删除给定学号的结点的函数。
(只编写删除子函数即可)3.编写函数实现动态链表的建立。
链表结点结构如下,要求在主函数中将你所建立的链表输出到屏幕上。
4.有10个学生,每个学生的信息包括学号、姓名、3门课的成绩,从键盘输入10个学生数据存入结构体数组中,要求输出个人总分最高的学生的信息(包括学号、姓名、3门课成绩、总分)。
5.链表的结点数据类型如下:struct node{int data;struct node *next;};链表的建立和输出函数如下,编写将第i个结点删除的函数,并完善主函数,调试运行整个程序。
struct node *creat(){ int x;struct node *h,*s,*r;h=(struct node *)malloc(sizeof(struct node));r=h;scanf("%d",&x);while(x!=-1){ s=(struct node*)malloc(sizeof(struct node));s->data=x;r->next=s;r=s;scanf("%d",&x);}r->next=NULL;return h;}void print(struct node *h) //打印函数{ struct node *p;p=h->next;if(p==NULL)printf("list is empty!");else{ while(p!=NULL){ printf("%4d",p->data);p=p->next;}}}并输出其平均成绩。
7.试利用指向结构体的指针编制一程序,实现输入三个学生的学号、数学期中和期末成绩,然后计算其平均成绩并输出成绩表。
8.有一个unsigned long型整数,现要分别将其前2个字节和后2个字节作为两个unsigned int型整数输出(设一个int型数据占2个字节),试编一函数partition实现上述要求。
要求在主函数中输入该long型整数,在函数partition中输出结果。
9.编写一个函数print,打印一个学生的成绩数组,该数组中有5个学生的数据记录,每个记录包括num、name、score[3],用主函数输入这些记录,用print函数输出这些记录。
用结构体共用体来实现。
10.有10个学生,每个学生的数据包括学号、姓名、3门课的成绩,从键盘输入10个学生数据,要求打印出3门课总平均成绩(指全体学生所有成绩的平均值),以及最高分的学生的数据(包括学号、姓名、3门课成绩、平均分数)。
用结构体来实现。
11.有一个结构体变量stu,内含学生学号、姓名和3门课的成绩。
要求在main函数中赋以值,在另一函数print中将它们打印输出。
用结构体变量作函数参数。
12.对候选人得票的统计程序。
设有3个候选人,有20个人对其进行投票,每次输入一个得票的候选人的名字,要求最后输出各人得票结果。
用结构体的方法实现。
13.定义一个结构体变量(包括年、月、日)。
计算该日在本年中是第几天?注意闰年问题。
14.请删除已知链表中的指定结点。
要求删除的结点数据从键盘输入。
#define NULL 0struct student{long num;float score;struct student *next;};main(){struct student a,b,c,*head,*p;a.num=99101; a.score=89.5;b.num=99103; b.score=90;c.num=99107; c.score=85;head=&a;a.next=&b;b.next=&c;c.next=NULL;p=head;do{printf("%ld %5.1f\n",p->num,p->score);p=p->next;}while(p!=NULL);del();/*请完成此函数来删除某一结点*/}答案:略15.请在已知链表中插入某一指定结点。
要求插入的结点数据从键盘输入,顺序按学号升序插入。
#define NULL 0struct student{long num;int score;struct student *next;};main(){struct student a,b,c,*head,*p;a.num=99101; a.score=89;b.num=99103; b.score=90;c.num=99107; c.score=85;head=&a;a.next=&b;b.next=&c;c.next=NULL;p=head;do{printf("%ld %5d\n",p->num,p->score);p=p->next;}while(p!=NULL);insert();/*请完成此函数来插入某一结点*/}答案:略16.请编写程序动态生成一个链表。
要求结点数据从键盘输入。
并将建立好的链表输出到屏幕上。
结点数据类型如下:struct student{long num;int score;struct student *next;};答案:略17.定义一个结构体变量(包括年、月、日)。
计算该日在本年中是第几天?注意闰年问题。
请写一函数days来完成此功能。
要求由主函数将年、月、日传递给days函数,计算后将日子数传回主函数输出。
答案:略18.有两个链表a和b。
设结点中包含学号、姓名。
从a链表中删去与b链表中有相同学号的那些结点。
链表a的数据:{"101","wang"},{"102","li"},{"105","zhang"},{"106","wei"}链表b的数据:{"103","chang"},{"104","ma"},{"105","zhang"},{"107","guo"},{"108","liu"}19.建立一个链表,每个结点包括:学号、姓名、性别、年龄。
输入一个年龄,如果链表中的结点所包括的年龄等于此年龄,将此结点删去。
请完善程序。
#include <malloc.h>#define NULL 0#define LEN sizeof(struct student)struct student{ char num[8];char name[10];char sex[2];int age;struct student *next;}stu[10];main(){struct student *p,*pt.*head;int i,length,iage,flag=1;int find=1;while(flag==1){ printf("input list's length (<10):\n");scanf("%d",&length);if(length<10)flag=0;}/*请完成建立链表*//*输出*/p=head;printf("\n num name sex age \n");while(p!=NULL){ printf("%8s%8s8s%8d\n",p->num,p->name,p->sex,p->age);p=p->next;}/*请完成删除*//*输出*/p=head;printf("\n num name sex age \n");while(p!=NULL){ printf("%8s%8s8s%8d\n",p->num,p->name,p->sex,p->age);p=p->next;}}20.以下为有3名学生数据的单向动态链表的综合操作。
今给出main函数、建立链表函数creat、链表输出函数print。
建立链表时输入各结点的数据按学号增序排列,使建立的链表有序。
请完善程序,要求编写按学号顺序插入结点的函数insert。
#include <malloc.h>#define NULL 0#define LEN sizeof(struct student)struct student{ long num;int score;struct student *next;};int n;struct student *creat(void) /*要求按学号递增顺序输入*/{ struct student *head;struct student *p1,*p2;n=0;p1=p2=(struct student*) malloc(LEN);scanf("%ld,%d",&p1->num,&p1->score);head=NULL;while(p1->num!=0){ n=n+1;if(n==1) head=p1;else p2->next=p1;p2=p1;p1=(struct student*)malloc(LEN);scanf("%ld,%d",&p1->num,&p1->score);}p2->next=NULL;return(head);}void print(struct student *head){ struct student *p;printf("\nNow,These %d records are:\n",n);p=head;if(head!=NULL)do{ printf("%ld %d\n",p->num,p->score);p=p->next;}while(p!=NULL);}struct student *insert(struct student *head,struct student *stud){}main(){ struct student *head,stu;printf("Input records:\n");head=creat();print(head);printf("\ninput the inserted record");scanf("%ld,%d",&stu.num,&stu.score);head=insert(head,&stu);print(head);getch();}21.有两个链表a和b。