輸入多名學生的語文數學英語體育成績
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);}