输入多名学生的语文数学英语体育成绩
1. 输入一个同学的成绩,英语、数学、语文、体育、计算平均分、最高分和最低分、如果有不及格请给出提示。
语文98 数学98 英语98 体育 满分 平均:(98+98+98+100)/4=98.5 最高100 最低98
2. 用C语言输入函数把10个学生的语文,英语,数学,体育,计算机5门课程成绩放在一个组里,成绩由键盘输入
首先建立一来个结构体:
struct student
{
double m_chinese;
double m_english;
double m_math;
double m_sport;
double m_computer;
} //这就构成了一个源学生的成绩信息
然后建立一个结构体数组: student stu[10];
然后就可以将学生信息用循环输入:
for(int i = 0; i< 10, i++)
{
cout << "Please input the chinese score:" << endl;
cin >> stu[i].m_chinese;
//其他四个同此,中间可以加入一些判读是否合法的语句
}
3. 求用C语言设置一个循环输入多个学生的语文、数学和英语成绩,并分别统计显示3个学科的平均成绩和总成绩!
利用一个标志循环 然后 用 count 记录 人数 sum1 sum2 sum3 分别统计 语文 数学 英语的总成绩 就行了回嘛
int count = sum1 = sum2 = sum3 = 0;
char ch = scanf("%c",&ch);
while(ch == 'y' || 'Y'){
int chinese = scanf("%d",&chinese);
sum1 += chinese;
..... // 自己加上答数学和英语
ch = scanf("%c",&ch);
count ++;
}
int ave = sum / count;
这样应该差不多了 很久没写C了 都不太记得格式了
4. 2、输入:运用输入函数把10个学生的语文、英语、数学、体育、计算机5门课程的成绩放在一个数组,成绩由键盘
定义一个结构体,在主函数中调用即可
5. c++:输入20个学生的语文,数学,英语成绩,求出总成绩,并输出这20个学生总成绩的排名
#include<stdio.h>
#defineN5
struct Student //学生数据
{
intChinese;
intmaths;
intEnglish;
intscore; //总分
}students[N];
struct Rank //用作记录排名数据
{
intscore;
intuser;
}rankList[N];
voidfun(structStudentstudents[N])
{
inti,j,k;
inttmp;
for(i=0;i<N;i++) //按学号顺序即输入成绩时的顺序求各学生总成绩
{
students[i].score+=students[i].Chinese;
students[i].score+=students[i].maths;
students[i].score+=students[i].English;
}
printf("成绩表:
");
for(i=1;i<N+1;i++)//将成绩表按学号顺序打印出来
{
printf(" Score%d=%d
",i,students[i-1].score);
}
for(i=0,k=0;i<N;i++)
{
tmp=0;
for(j=0;j<N;j++)
{
if(tmp<students[j].score)
{
tmp=students[j].score;//每次都将最大值赋给tmp变量
}
}
rankList[i].score=tmp; //按顺序将最高分赋值给rankList结构体成员score
for(j=0;j<N;j++)
{
if(students[j].score==tmp)//比较并记录本次循环的最高分是哪位学生
{
students[j].score=0;//每循环一次,将最高分置零
rankList[k++].user=j+1;//并记录最高分对应的学生学号
}
}
}
printf("
排名表:
");
printf(" Ranking: StudentID:
");
for(i=1;i<N+1;i++) //输出排名表
{
printf(" 第%d名 ",i);
printf(" user%d
",rankList[i-1].user);
}
}
intmain()
{
int i;
for(i=1;i<N+1;i++)//给每位学生打分,即输入数据
{
printf("student%d:
",i);
printf(" Chinese=");
scanf("%d",&students[i-1].Chinese);
printf(" maths=");
scanf("%d",&students[i-1].maths);
printf(" English=");
scanf("%d",&students[i-1].English);
}
printf("
");
fun(students); //调用函数fun
printf("
");
return0;
}
以上是我写的程序,在宏定义里面改变N的值可以任意设置学生人数。但是不完整,当有总分相同的时候名次是按学号排的,也就是总分相同的时候名次不一样。下面是运行结果
6. 输入一个同学的成绩,英语、语文、数学、体育,计算它的平均分、最高分和最低分,如果有不及格请给出提示
在Excel中,这些都是非常容易实现的。
设英语、语文、数学、体育分别在D、E、F、G列,回平均分在H列
第一个学答生的成绩在第5行
平均分:在H5单元格中输入:=sum(d5:g5) /4 (4 个科目)
若有50名学生
最高分:在D58内输入:=max(d5:d54)
最低分:在D59内输入:=min(d5:d54)
7. 编程实现从键盘连续输入多名同学的学号,姓名,语文,数学,英语成绩,并计算出总成绩,当输入学号为0时
#include "stdio.h"
struct student
{ char num[6];
char name[8];
int score[3];
float avr;
} stu[5];
main()
{int i,j,sum;
FILE *fp;
/*input*/
for(i=0;i<5;i++)
{ printf("\n please input No. %d score:\n",i);
printf("stuNo:");
scanf("%s",stu[i].num);
printf("name:");
scanf("%s",stu[i].name);
sum=0;
for(j=0;j<3;j++)
{ printf("score %d.",j+1);
scanf("%d",&stu[i].score[j]);
sum+=stu[i].score[j];
}
stu[i].avr=sum/3.0;
}
fp=fopen("stud","w");
for(i=0;i<5;i++)
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}
8. 输入8个同学学号和语文、数学、英语成绩,按总分从低到高输出学号和语文、数学、英语成绩。
#include"stdio.h" //输入信息函数
int input(int score[][4],char name[][15])
{
int n,i;
printf("请输入学生个数:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("请输入第%d个学生的名字、高数成绩、英语成绩、C语言成绩:\n",i+1);
scanf("%s%d%d%d",&name[i],&score[i][0],&score[i][1],&score[i][2]);
//输入时数据间用空格间隔
score[i][3]=score[i][0]+score[i][1]+score[i][2];
}
return n;
}
//排序并输出函数
void paixu(int score[][4],char name[][15],int n){
int i,j,temp,score1[50];
char tem[15];
for(i=0;i<n;i++)
score1[i]=score[i][3];
for(j=0;j<n;j++)
for(i=0;i<n-j;i++)
if(score1[i]<score1[i+1])
{temp=score1[i];
score1[i]=score1[i+1];
score1[i+1]=temp;
strcpy(tem,name[i]);
strcpy(name[i],name[i+1]);
strcpy(name[i+1],tem);}
for(i=0;i<n;i++)
printf("序号:%d 姓名:%s 语文:%d 数学:%d 英语:#d\n",i+1,name[i]);
}
//主函数
void main(){
int score[50][4];
char name[50][15];
int n=input(score,name);
paixu(score,name,n);
}
程序有点乱,我没C++程序,你试试吧,应该是对的。
9. 输入三个学生的成绩,数学英语语文,要求输出各科的平均值,最高分的同学的信息
creat函数写错了,指针没搞好
我改了一下,你对照着你原来的看一下,有问题再追问吧!
#include <stdio.h>
#include <malloc.h>
#define LEN sizeof(struct student)
typedef struct student
{
long num;
float chinese;
float math;
float engish;
struct student *next;
}Score;//结构体
Score *creat()
{
struct student *head;
struct student *p1,*first;
int n=0;
p1=(struct student *)malloc(sizeof(Score));
head=p1;
p1=first=(struct student *)malloc(sizeof(Score)); printf("请输入:\n");
scanf("%ld,%f,%f,%f",&p1->num,&p1->chinese,&p1->math,&p1->engish);
head->next=p1;
first=head->next;
while(n<2)
{
p1=(struct student *)malloc(LEN);
printf("请输入:\n");
scanf("%ld,%f,%f,%f",&p1->num,&p1->chinese,&p1->math,&p1->engish);
first->next=p1;
first=first->next;
n=n+1;
}
first->next=NULL;
return(head);
}//建立链表
void average(struct student *head)
{
struct student *p1;
float t=0,j=0,k=0;
p1=head->next;
while(p1!=NULL)
{
t=t+p1->chinese;
j=j+p1->engish;
k=k+p1->math;
p1=p1->next;
}
t=t/3;
j=j/3;
k=k/3;
printf("chinese:%5.1f\n,math:%5.1f\n,engish%5.1f\n",t,j,k);
}//求平均值
void max(struct student *head)
{
struct student *p,*p1;
float t,max=0;
int i;
p=head->next;
for (i=0;i<3;i++)
{
t=p->chinese+p->engish+p->math;
if(max<t) {max=t;p1=p;}
p=p->next;
}
printf("最高分:%5.2f \n %ld %5.1f %5.1f %5.1f\n",t,p1->num,p1->chinese,p1->math,p1->engish);
}
void main()
{
struct student *head;
head=creat();
average(head);
max(head);
}
10. 输入八名学生的语文数学英语C语言四门课程成绩,要求输出每名同学的
creat函数写错了,指针没搞好我改了一下,你对照着你原来的看一下,有问题再追问吧!#include#include#defineLENsizeof(structstudent)typedefstructstudent{longnum;floatchinese;floatmath;floatengish;structstudent*next;}Score;//结构体Score*creat(){structstudent*head;structstudent*p1,*first;intn=0;p1=(structstudent*)malloc(sizeof(Score));head=p1;p1=first=(structstudent*)malloc(sizeof(Score));printf("请输入:\n");scanf("%ld,%f,%f,%f",&p1->num,&p1->chinese,&p1->math,&p1->engish);head->next=p1;first=head->next;while(nnum,&p1->chinese,&p1->math,&p1->engish);first->next=p1;first=first->next;n=n+1;}first->next=NULL;return(head);}//建立链表voidaverage(structstudent*head){structstudent*p1;floatt=0,j=0,k=0;p1=head->next;while(p1!=NULL){t=t+p1->chinese;j=j+p1->engish;k=k+p1->math;p1=p1->next;}t=t/3;j=j/3;k=k/3;printf("chinese:%5.1f\n,math:%5.1f\n,engish%5.1f\n",t,j,k);}//求平均值voidmax(structstudent*head){structstudent*p,*p1;floatt,max=0;inti;p=head->next;for(i=0;ichinese+p->engish+p->math;if(maxnext;}printf("最高分:%5.2f\n%ld%5.1f%5.1f%5.1f\n",t,p1->num,p1->chinese,p1->math,p1->engish);}voidmain(){structstudent*head;head=creat();average(head);max(head);}