1、&(q-year)%100!=0)|(q-year)%400=0) if(p-monthmonth2) total+; else if(years!=0) for(i=p-12;i+)total+=monthdayi; for(i=0; total+=q-year+1;year); total+=365; if(i%4=0&i%100!=0)|i%400=0) if(p-year%4=0&p-year%100!=0)|p-year%400=0)&=2)total+;=0)|q-2)total+; return total;void main() int days; printf(please
2、input date1(year,month,day):); scanf(%d,%d,%d,&date1.year,&date1.month,&date1.day);please input date2(year,month,day):date2.year,&date2.month,&date2.day); days=totaldays(&date1,&date2);days=%dn,days);2.结构体数组应用请定义一个描述学生基本信息的结构,包括姓名,学号,籍贯,身份证号,年龄,家庭住址,性别,联系方式等。并定义一个结构体数组。编程:a)编写函数 input() , 输入基本信息(35条
3、记录);b)编写函数 print(),输出全体记录信息;c)编写函数 search(), 检索一个指定的学生信息并返回, 由主函数打印到屏幕上;d)说明,访问结构的时候,什么时候应该用运算符“.”,什么时候应该用运算符“-”。string.hstruct studentchar name20;int num;char home20;char IDnum20;int age;char addr50;char sex;char phone20;stu10;void input(struct student *p)%s %d %s %s %d %s %c %sname,&num,&home,&IDn
4、um,&age,&addr,&sex,&phone);void print(struct student *p)%s,%d,%s,%s,%d,%s,%c,%sn,p-name,p-num,p-home,p-IDnum,p-age,p-addr,p-sex,p-int search(struct student stu,int n,char stu_name20) int i; for(i=0;n; if(strcmp(stu_name,stui.name)=0)return i;break; else continue; return n+1; int n,i; char a20;please
5、 input the number of the students:%dn);i+)input(&stui);i+)print(&please input the name of the student you want to search:n%sa); i=search(stu,n,a); if(i#define LEN sizeof(struct poly)struct polyint c;int e;struct poly *next;poly110,poly210;void input(struct poly a,int m) for(int i=0;m; scanf(%d,%dai.
6、c,&ai.e);struct poly *linkcreate(struct poly a,int m) struct poly *head; struct poly *p1,*p2; p1=p2=(struct poly*)malloc(LEN); head=p1=&a0; p2=&ai;p1-next=p2;p1=p2; p1-next=NULL; return(head);void linkprint(struct poly *head) struct poly *p;the polynomial: p=head; if(head!=NULL) do printf(%dx%dc,p-e
7、); p=p-next; if(p!=NULL)putchar(+ while(p!=NULL); putchar(nstruct poly* add(struct poly *head1,struct poly *head2) struct poly *p1,*p2,*p3,*p4; p1=p2=p3=p4=(struct poly*)malloc(LEN); p2=head2; do p1=head1; while(p1! if(p2-e=p1-e) p1-c=p1-c+p2-c; p4=p2; p2=p2- p1=head1; else p3=p1; p1=p1- while(p2-ee
8、)&(p1-next!=NULL) p3=p1;p1=p1- p4=p2; p2=p2- if(p4-enext=p4; p4-next=p1; elsep1-p4- while(p2! return (head1);void addprint(struct poly *head) struct poly *p1;the new polynomial: p1=head;,p1-c,p1- if(p1! putchar( int m,n; struct poly *p,*q,*head;please input the number of first terms:m); input(poly1,
9、m); p=linkcreate(poly1,m); linkprint(p);please input the number of second terms: input(poly2,n); q=linkcreate(poly2,n); linkprint(q); head=add(p,q); addprint(head); 4.循环淘汰 有N个同学,编号分别为1,2,3,N,围成一圈,随便选定一个整数m,让大家按顺时针依次报数,报到m的同学便会从圈子中退出,从而被淘汰,直到最后剩下一个人。编写函数实现上述循环淘汰功能。编写一个程序测试上述函数的功能,要求用户能够任意输入N与m;程序输入最后
10、剩下人的编号。#define LEN sizeof(struct student) int num; struct student *next;int win(int n,int m) struct student *p,*p1,*p2,*head; p=(struct student*)malloc(LEN); head=p;i+)/建立链表 p-num=i+1; p1=p; p=(struct student*)malloc(LEN); p1-next=p;next=head;p1=head; while(p1-=p1)/开始删除元素 i=1; p1=p; i=i+1; while(i!=
11、m); p2=p1; p2-next=p- p=p- return(p1-num); int N,m,num;please input N,m:N,& num=win(N,m);the winner is NO.%d.,num);5.工资单处理 (1) 编写函数:有两个单向链表,头指针分别为list1、list2,链表中每一结点包含员工号(员工号为关键字段,不重复)、姓名、工资基本信息,请编一函数,把两个链表拼组成一个链表,并返回拼组后的新链表,按员工号升序排列。 (2)编写函数:利用指针数组,实现按照工资进行升序排列的功能。返回排序完成的指针数组 (3)编写一程序,分别输出按员工号排序后的新
12、链表,以及按照工资排序的结果。假设链表list1初始化内容为:002, name002,3000, 005, name005,2500, 003, name003,3500链表list2初始化内容为:006, name006,2800, 004, name004,3700, 001, name001,3000, 007, name007, 3600, struct staff char num5; char name10; int wages; struct staff *next;a3=003,name003,3500,NULL,a2=005name005,2500,&a3,a1=002na
13、me002,3000,&a2,b4=007name007,3600,NULL,b3=001name001b4,b2=004name004,3700,&b3,b1=006name006,2800,&b2;struct staff *rank_num(struct staff *list1,struct staff *list2) struct staff *head,*p1,*p2,*p3,*p4; head=NULL;p1=list1; p4=p1; while(p4! /*老师,我在这题的想法是把它一个一个卸下来然后按顺序装到另一个头指针后,但是感觉这样拆开很麻烦,尤其是我在插入的时候需要定
14、义四个指针,做着做着就乱了,有什么更好的办法吗?*/ if(head=NULL)head=p1;p2=p1;p2- while(strcmp(p1-num,p2-num)0& p3=p2; p4=p1; if(strcmp(p1-num) p4=p1- p1=p4; else p2- p1=list2; p4=list2; while(p4! p2=head;struct staff *rank_pay(struct staff *head) struct staff *p1,*p2,*p3,*p4,*head2; head2=NULL; while(p1! p2=head2; if(head2=NULL)head2=p1; while(p1-wageswages)& if(p1-wagesname); p3=head; while(p1-nump3-num& p4=p3;p3=p3- if(p1-num p1-next=p3; else p3-next=N
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1