链表真题2014

有一个链表,节点包含学号,成绩,指向下一个节点的结构体指针,写一个函数实现,输出成绩高于平均成绩的学生学号。

#include<stdio.h>
#include <stdlib.h>
typedef struct stuNode{
	int id;
	double score;
	stuNode *next;
}stu;
void printaboveaverage(stu *head){
	stu *s=head->next;
	
	double sumscore;
	int count;
	for(int i=0;i<3;i++){
		sumscore+=s->score;
		count++;
		s=s->next;
	}
	double ave=sumscore/count;
	printf("均分为 %lf\n",ave);
	stu *s1=head->next;
	while(s1!=NULL){
		if(s1->score>ave){
			printf("成绩高于均分的学号:%d",s1->id);
		}
		s1=s1->next;
	}
}
int main()
{
	stu *head,*p,*q;
	head=(stu *)malloc(sizeof(stu));
	head->next=NULL;
	q=head;
	int n;
	long a;
	double b;
	for(int i=0;i<3;i++){
		p=(stu *)malloc(sizeof(stu));
		scanf("%d,%lf",&a,&b);
		p->id=a;
		p->score=b;
		printf("学号和分数为:%d,%lf\n",p->id,p->score);
		q->next=p;
		q=p;
	}
	q->next=NULL;
	
	printaboveaverage(head);
	 
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值