编写一个程序,输入n个学生的学号,姓名,3门课程的成绩,求出总分最高的学生并输出该学生的所有信息,

2024-11-17 16:34:37
推荐回答(3个)
回答1:

看看这个,应该符合你的要求:

///////////////////////////////////////
/* */
/* by autorun_inf */
/* */
///////////////////////////////////////

#include

struct student
{
int no; //学号
char name[10];
float math,english,computer; //三门课程的成绩
double total; //总成绩
double avr; //平均成绩
};

struct student stu[50]; //声明一个结构数组变量

struct student input();
void display(struct student stud[],int count);
void sort(struct student stud[],int count);

void main()
{
int count;
char ch;
ch='y';

printf("请按以下格式输入学生信息(可用Tab键对齐):");
printf("\n");
count=0;
while ((ch=='y') || (ch=='Y'))
{
stu[count]=input(); //调用录入信息函数
count++;
printf("\n是否继续?(按Y继续,其它结束)");
scanf(" %c",&ch);
}
printf("\n最高分为:");
sort(stu,count); //调用排序函数
display(stu,1); //调用显示信息函数

}

struct student input() //录入信息函数
{
struct student studn;

printf("\n学号\t姓名\t数学\t英语\t计算机\n");
scanf("%d%s%f%f%f",&studn.no,studn.name,&studn.math,&studn.english,&studn.computer);

studn.total=studn.math+studn.english+studn.computer;
studn.avr=studn.total/3.0;

return studn;
}

void display(struct student stud[],int count) //显示信息函数
{
int i;
printf("\n学号\t姓名\t数学\t英语\t计算机\t总分\t平均分");
printf("\n");
for(i=0;i {
printf("%d",stud[i].no);
printf("\t%s",stud[i].name);
printf("\t%.1f",stud[i].math);
printf("\t%.1f",stud[i].english);
printf("\t%.1f",stud[i].computer);
printf("\t%.2f",stud[i].total);
printf("\t%.2f",stud[i].avr);
printf("\n");
}
}

void sort(struct student stud[],int count) //排序函数
{
int i,j;

/* 冒泡排序法*/
struct student t;
for(i=0;i for(j=0;j {
if(stud[j].avr {
t=stud[j];
stud[j]=stud[j+1];
stud[j+1]=t;
}
}
}

回答2:

作业吧!
又想不劳而获……
过程才是编程的快乐哟!

回答3:

#include "stdio.h"
#include "string.h"
#define NULL 0
typedef struct node
{long num;
char name[4];
float eng,math,com,total,ave;
struct node *next;
}LNode,*LinkedList;

LinkedList LinkedListCreat(LinkedList L )
{ LinkedList L,p,r,s,q;
int x,flag=-1;
float e,m,c;

printf("Please enter student numbers, input of -1 End \n");
scanf("%ld",&x);
while (x!=flag)
{ q=L;s=q->next;
while(s!=NULL&&s->num!=x)
{q=s; s=s->next;}
if(s==NULL)
{
p=(LinkedList)malloc(sizeof(LNode));
printf("Input student's name:");
scanf("%s\n",p->name);
printf("Input student's english:");
scanf("%f\n",&e);
printf("Input student's mathe:");
scanf("%f\n",&m);
printf("Input student's computer:");
scanf("%f\n",&c);
p->num=x;
p->eng=e;
p->math=m;
p->com=c;
p->total=(e+m+c);
p->ave=p->total/3.0;
if(L->next==NULL)
{ r=L;
r->next=p;
r=p;
r->next=NULL;
}
else
{q=L;s=q->next;
while(s!=NULL&&s->total>p->total)
{q=s; s=s->next;}
p->next=q->next; q->next=p;}
}
else
printf("have the same num,Resume load!\n ");
printf("Please enter student numbers, input of -1 End \n");
scanf("%ld",&x);
}
return L;
}

void print(LinkedList L) /*输出链表中的结点*/
{LinkedList p;
p=L->next;
printf("num\tname\tEnglish\t\tmathe\tcomputer\ttotal\tave\n");
while(p!=NULL)
{
printf("%ld\t%s\t%.2f\t\t%.2f\t%.2f\t\t%.2f\t%.2f\t\n",p->num,p->name,p->eng,p->math,p->com,p->total,p->ave);
p=p->next;
}
}

main( )
{LinkedList L;
L=(LinkedList)malloc(sizeof(LNode));
L->next=NULL;

L=LinkedListCreat( L);
print(L);
}