#include<stdio.h>
#include<malloc.h>
#include<conio.h>
struct student
{
double score;
struct student *next;
};
main()
{
struct student *head,*tail,*p;
double num,sum,t,a,c;
head=tail=NULL;
printf("请输入成绩并以负数结束:/n");
scanf("%lf",&num);
while(num>0.0)
{p=(struct student *)malloc(sizeof(struct student));
p->score=num;
if(head==NULL)
head=p;
else
tail->next=p;
tail=p;
scanf("%lf",&num);
}
tail->next=NULL;
p=head;
if(p!=NULL)
a=p->score;
while(p->next!=NULL)
{
p=p->next;
c=a;
sum=sum+c;
c=p->score;
if(a>p->score)
{ t=p->score;
p->score=a;
a=t;}
a=p->score;
}
sum=sum+a;
printf("其和为:%.2lf/n",sum);
printf("最大值为:%.2lf",a);
getch();
}
输入成绩并以负数结束
最新推荐文章于 2023-03-19 15:14:17 发布