c语言求10个同学的3课成绩的平均分和最高值

有没有人在啊,想请说下,c语言求10个同学的3课成绩的平均分和最高值
最新回答
七月别困

2025-03-02 02:15:50

昨天刚做了道类似的,给你参考下
//从键盘输入几位同学,每名有学号(整型),姓名(字符串),数学成绩(整型),外语成绩(整型)和计算机成绩(整型)三门课程,
//计算每名学生的总成绩,然后按总成绩由高到低排序.若总成绩相同,按外语成绩由高到低排序,把排序后的结果输出.

#include<stdio.h>
#include<malloc.h>
#define NULL 0

struct student
{
int num;
char name[25];
int math;
int english;
int computer;
int total;
struct student *next;
}*head;

void input()
{
struct student *p, *q;
int n;

printf("你要输入多少位同学的信息 : ");
scanf("%d",&n);
for(int m=0; m<n; m++)
{
p = (struct student *)malloc(sizeof(struct student));
printf("\n第 %d 位同学的信息\n",m+1);
printf("姓名: ");
scanf("%s",&p->name);
printf("学号: ");
scanf("%d",&p->num);
printf("数学成绩: ");
scanf("%d",&p->math);
printf("外语成绩: ");
scanf("%d",&p->english);
printf("计算机成绩: ");
scanf("%d",&p->computer);
p->total = 0;
p->next = NULL;

if(m == 0)
{
head = p;
q = p;
}
else
{
q->next = p;
q = p;
}

}
}

void count()
{
struct student *pt;
int tot = 0;

if(head != NULL)
{
pt = head;

while(pt != NULL)
{
tot = pt->math + pt->english + pt->computer;
pt->total = tot;
pt = pt->next;
}
}
}

void order()
{
struct student *pp, *rear;
struct student *first = NULL;
int score = 0;

while(head != NULL)
{
pp = head;
head = head->next;
pp->next = NULL;

if(first == NULL) //first队列的第一个结点
{
first = pp;
rear = pp;
}
else
{

if(pp->total > first->total)//在first队列中分数最大
{
pp->next = first;
first = pp;
}
else
{
struct student *ppt = first;

while(ppt != NULL && ppt->total > pp->total)
{
ppt = ppt->next;
}

if(ppt == NULL) //在first目前队列中的最小,插队尾
{
rear->next = pp;
rear = pp;
}
else if(ppt->total < pp->total)
{
struct student *ppk = first;

while(ppk->next != ppt)
{
ppk = ppk->next;
}
pp->next = ppt;
ppk->next = pp;

}
else //总分相等时
{
struct student *ppn = first;

while(ppt != NULL && ppt->total == pp->total && ppt->english >= pp->english)
{
ppt = ppt->next;
}
if(ppt == NULL)
{
rear->next = pp;
rear = pp;
}
else if(ppt == first)
{
pp->next = first;
first = pp;
}
else
{
while(ppn->next != ppt)
{
ppn = ppn->next;
}
pp->next = ppt;
ppn->next = pp;
}
}//else+
}//else++
}//else+++
}//while

head = first;
}

void display()
{
struct student *pw = head;
printf("学号\t");
printf("姓名\t");
printf("数学\t");
printf("英语\t");
printf("计算机\t");
printf("总分\n");
while(pw != NULL)
{
printf("%d\t",pw->num);
printf("%s\t",pw->name);
printf("%d\t",pw->math);
printf("%d\t",pw->english);
printf("%d\t",pw->computer);
printf("%d\n",pw->total);

pw = pw->next;
}
}

void main()
{
input();
count();
order();
display();
}
听海的哭泣ぃ

2025-03-02 00:37:37

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define NN 10 // 10 是学生人数上限 。可自己调整。
#define SC 3 // 4 课程数。
typedef struct student{
int no;
char name[10];
double score[SC];
double total;
double avg;
};
student stu[NN+1];

double search(int n)
{ int i,j;
double max;
max=0;
for(i=1;i<=n;i++)
for(j=0;j<SC;j++)
if(stu[i].score[j]>max)max=stu[i].score[j];
return max;
}

int main()
{
int i,j,k,n,m,l;
double ma=0,temp,avgscore[SC],ssscore;
// char sname[4][10]={"语文","数学","英语","综合"} ;
printf("输入学生人数(<=%d):",NN);
scanf("%d",&n);
while(n>NN){
printf("超出允许范围(<=%d),请重新输入:",NN);
scanf("%d",&n);}
for(i=1;i<=n;i++)
{
printf("输入第%d个学生姓名:",i);
fflush(stdin);
gets(stu[i].name);
printf("输入第%d个学生成绩 ",i);
stu[i].total=0;
stu[i].avg=0;
for(j=0;j<SC;j++){
scanf("%lf",&stu[i].score[j]);
stu[i].total+=stu[i].score[j];
}
stu[i].avg=stu[i].total/SC;
}
system("cls");
printf("\n\n\n\n");
ma=search(n);
for(i=1;i<=n;i++)
printf("学生:%2d %s \n总分:%.2lf \n平均分:%.2lf\n",i,stu[i].name,stu[i].total,stu[i].avg);
printf("所有成绩中最高分:%.2lf\n",ma);

system("pause");
return 0;
}
像个路人

2025-03-02 00:13:18

// shuzu.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
#define NUM 10
using namespace std;

struct stu
{
int course1;
int course2;
int course3;
};

void main()
{
int i=0;
int arg1=0,arg2=0,arg3=0;
int max1=0,max2=0,max3=0;
stu student[NUM];
cout<<"请输入课程1的成绩:";
for(i=0;i<NUM;i++)
{
cin>>student[i].course1;
}
cout<<"请输入课程2的成绩:";
for(i=0;i<NUM;i++)
{
cin>>student[i].course2;
}
cout<<"请输入课程3的成绩:";
for(i=0;i<NUM;i++)
{
cin>>student[i].course3;
}

for(i = 0;i<NUM;i++)
{
arg1+=student[i].course1;
arg2+=student[i].course2;
arg3+=student[i].course3;
}
arg1=arg1/NUM;
arg2=arg2/NUM;
arg3=arg3/NUM;
cout<<"arg1="+arg1;
cout<<"arg2="+arg2;
cout<<"arg3="+arg3;
max1=student[0].course1;
max2=student[0].course2;
max3=student[0].course3;
for(i = 0;i<NUM;i++)
{
if(student[i].course1>max1)max1=student[i].course1;
if(student[i].course2>max2)max2=student[i].course2;
if(student[i].course3>max3)max3=student[i].course3;
}
cout<<"max1="+max1;
cout<<"max2="+max2;
cout<<"max3="+max3;
}
_蓝色丶夜☆空★

2025-03-02 01:06:20

main()
{
float a,b,c,p,max,i; //把平均定为p,最高定为max
for (i=1;i<=10;i++)
{scanf("%f,%f,%f",&a,&b,&c);
p=(a+b+c)/3;
printf("the average is %f\n",p);
if(a>=b&&a>=c),max=a;
if(b>=a&&b>=c),max=b;
if(c>=a&&c>=b),max=c;
}
printf("the max is %f\n",max);
}
ヽ冷艳°皇后

2025-03-02 03:12:29

#include <stdio.h>
void main()
{
printf("welcome to this program!\n");
printf("please the first student's score");
printf("please the first student's score");
printf("please the first student's score");
printf("please the first student's score");
printf("please the first student's score");