华夏财富网

网站首页 新知 > 正文

c语言程序设计实验报告怎么写(c语言程序设计实验报告)

2022-08-11 00:09:35 新知 来源:
导读 大家好,小福来为大家解答以上的问题。c语言程序设计实验报告怎么写,c语言程序设计实验报告这个很多人还不知道,现在让我们一起来看看吧!1...

大家好,小福来为大家解答以上的问题。c语言程序设计实验报告怎么写,c语言程序设计实验报告这个很多人还不知道,现在让我们一起来看看吧!

1、代码:# include # include char stu_no[10][10]; int c_math[10],c_en[10],c_computer[10],point[10],average[10]; int i,j,max; char c; void input() { for(i=0;i<=9;i++) /*输入学生成绩*/ { printf("请输入学号:"); scanf("%s",&stu_no[i]); printf("请输入数学成绩:"); scanf("%d",&c_math[i]); printf("请输入英语成绩:"); scanf("%d",&c_en[i]); printf("请输入计算机基础成绩:"); scanf("%d",&c_computer[i]); } for(i=0;i<=10;i++) /*计算总分跟平均分*/ { point[i]=c_math[i]+c_en[i]+c_computer[i]; average[i]=point[i]/3; } } void paixu() { printf("成绩按从高到低排列为:"); printf("学号 数学 英语 计算机基础 总分 平均分"); for (i=0;i<=10;i++) { for(j=1;j<=10;j++) if (point[i]>point[j]) max=i; printf("%s,d,%d,%d,%d,%d,%d",stu_no[max],c_math[max],c_en[max],c_computer[max],point[max],average[max]); } } void main() { input(); paixu();}用链表:#include #include #ifndef NULL#define NULL 0#endif#define LEN sizeof(struct student)struct student{ long num; float 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,%f",&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,%f",&p1->num,&p1->score); } p2->next=NULL; return(head);}void print(struct student *head){ struct student *p; printf("Now,These %d records are:",n); p=head; if(head!=NULL) do { printf("%ld %5.1f",p->num,p->score); p=p->next; }while(p!=NULL);}struct student *del(struct student *head,long num){ struct student *p1, *p2; if(head==NULL){printf("list null!");return NULL;} p1=head; while(num!=p1->num && p1->next!=NULL) {p2=p1;p1=p1->next;} if(num==p1->num) { if(p1==head) head=p1->next; else p2->next=p1->next; printf("delete:%ld",num); n=n-1; } else printf("%ld not been found!",num); return(head);}struct student *insert(struct student *head, struct student *stud){ struct student *p0,*p1,*p2; p1=head; p0=stud; if(head==NULL) {head=p0;p0->next=NULL;} else { while((p0->num > p1->num) && (p1->next != NULL)) { p2=p1; p1=p1->next; } if (p0->num <= p1->num) { if(head==p1) head=p0; else p2->next=p0; p0->next=p1; } else {p1->next=p0;p0->next=NULL;} } n=n+1; return head;}void main(){ struct student *head, *stu; long del_num; printf("input records:"); head=creat(); print(head); printf("input the deleted number:"); scanf("%ld",&del_num); while(del_num!=0) { head=del(head,del_num); print(head); printf("input the deleted record:"); scanf("%ld",&del_num); } printf("input the inserted record:"); stu=(struct student *)malloc(LEN); scanf("%ld,%f",&stu->num,&stu->score); while(stu->num!=0) { head=insert(head,stu); print(head); printf("input the inserted record:"); stu=(struct student *)malloc(LEN); scanf("%ld,%f",&stu->num,&stu->score); }}挺好的。

本文到此分享完毕,希望对大家有所帮助。


版权说明: 本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。


标签:




热点推荐
热评文章
随机文章