當前位置:首頁 » 編程語言 » c語言輸入員工名字和成績
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言輸入員工名字和成績

發布時間: 2023-02-17 22:42:55

c語言題目:讓用戶輸入5個人名字以及其成績,求最高分是多少,對應的學生姓名是。

#include<stdio.h>

structstudent
{
charname[20];
intscore;
};

intmain()
{
inti;
intmaxi=0;
intmaxscore=0;
structstudentstu[5];

for(i=0;i<5;i++)
{
printf("請輸入名字:");
scanf("%s",stu[i].name);
printf("請輸入成績:");
scanf("%d",&stu[i].score);
if(i==0)
{
maxi=0;
maxscore=stu[i].score;
}
else
{
if(maxscore<stu[i].score)
{
maxscore=stu[i].score;
maxi=i;
}
}
}

printf("最高分是:%d ",stu[maxi].score);
printf("名字是:%s ",stu[maxi].name);

return0;
}

⑵ c語言中根據姓名查詢成績

#include "conio.h"
struct student
{
char name [15];
int score;
};
int find (struct student s[]);void main()
{
int i=0;
struct student stu[5];
for(i=0;i<5;i++)
{
printf("輸入第%d個學生的姓名:",i+1);
scanf("%s",stu[i].name);
printf("輸入第%d個學生的成績:",i+1);
scanf("%d",&stu[i].score);
}
int nIndex=find(stu);
if(nIndex!=-1)
printf("找到該同學信息,該同學位於第%d個位置(數組下標)",nIndex);
getch();
}int find(struct student s[])
{
char name[15];
int i=0;
int nIndex=-1;
printf("輸入要查詢學生的姓名:");
scanf("%s",name);
for(i=0;i<5;i++)
{
if(strcmp(s[i].name,name)==0)
{
nIndex=i;
break;
}
}
return nIndex;
}

⑶ 求C語言程序大神!

#include<stdio.h>
#defineN1000//預定義員工個數

/*定義員工結構體*/
structEmployee
{
charID[20];
charName[20];
floatMark1;
};

/*聲明員工數組及員工數量*/
structEmployeeEmployees[N];
intnum=0;

/*插入員工信息*/
intEmployee_Insert(){
while(1){
printf("請輸入員工ID:");
scanf("%s",&Employees[num].ID);
getchar();
printf("請輸入姓名:");
scanf("%s",&Employees[num].Name);
getchar();
printf("請輸入業績:");
scanf("%f",&Employees[num].Mark1);
getchar();
num++;
printf("是否繼續?(y/n)");
if(getchar()=='n'){
break;
}
}
returnnum;
}
/*按業績排序*/
voidEmployee_Sort(){
inti,j;
structEmployeetmp;
for(i=0;i<num;i++){
for(j=1;j<num-i;j++){
if(Employees[j-1].Mark1<Employees[j].Mark1){//降序
tmp=Employees[j-1];
Employees[j-1]=Employees[j];
Employees[j]=tmp;
}
}
}
}
/*顯示員工信息*/
voidEmployee_Display(){
inti,t;
printf("%10s%10s%20s ","工號","姓名","業績");//顯示格式可自行調整
printf("--------------------------------------------------------- ");
if(num>10)//員工不超過10人,全部顯示
//超過10人,顯示排序前10
t=10;
else
t=num;
for(i=0;i<t;++i){//顯示格式可自行調整
printf("%10s%10s%18.2f ",
Employees[i].ID,Employees[i].Name,Employees[i].Mark1);
}
}
/*主程序*/
intmain(){
Employee_Insert();//輸入員工信息
Employee_Sort();//排序
Employee_Display();
return0;
}

⑷ 一道簡單C語言:請編寫一個程序,從鍵盤輸入100名職工的職工號、姓名和工資,

#include<stdio.h>
#define NUM 100//把此處的宏定義成100就是你想要的100個職工了
struct WorkerInfo
{
char Number[10];
char name[10];
float wage;
};
float arg,*point=&arg;//為了正確使用浮點數,此處務必如此定義
void main()
{
struct WorkerInfo wi[NUM];
int i;
float sum=0;
for(i=0;i<NUM;i++)
{
printf("Please input the %d woker's information:",i+1);
scanf("%s",wi[i].Number); /* Number 為數組名,不加&*/
scanf("%s",wi[i].name);
scanf("%f",&wi[i].wage);
sum+=wi[i].wage;
}
printf("\nThe average wage is :%f\n",sum/NUM);
printf("Number name wage\n");
for(i=0;i<NUM;i++)
{
if(wi[i].wage<300.00)
printf("%s,%s,%6f\n",wi[i].Number,wi[i].name,wi[i].wage);
}
}
//樓主的程序完全正確,基本不用修改,
//可以把宏定義成3來驗證程序的正確與否,
//注意輸入的方式,先輸入數字,然後回車,
//再輸入名字再回車,再輸入工資,然後就會轉到第二個人了,不然會出錯的

⑸ c語言,輸入學生成績和名字,排序時怎麼才能讓名字跟著成績走

一開始就建兩個數組,一個放成績,一個放名字,如:charname[100][20];floatscore[100];以後輸入、輸出、排序等等操作,都把name和score看做不可分離的一組(類似於同一個i的結構體變數),讓name[i]和score[i]成為一對!排序時,當score[k]移動到m位置時,對應的name[k]也要同時移動的m位置。這樣,名字就跟著成績走了。

⑹ c語言編程,輸入5個人的名字,學號,成績,把高於60分的找出來

#include<stdio.h>
structstu{
charno[20];
charname[50];
intscore;
};
intmain()
{
structstus[5];
inti;
for(i=0;i<5;i++)
{
printf("input%dstudent'snumber:",i+1);
scanf("%s",s[i].no);
printf("input%dstudent'sname:",i+1);
gets(s[i].name);
printf("input%dstudent'sscore:",i+1);
scanf("%d",&s[i].score);
}
for(i=0;i<5;i++)
if(s[i].score>60)printf("%s%s%d ",s[i].no,s[i].name,s[i].score);
return0;
}

⑺ c語言:鍵盤輸入不大於50人的百分製成績和姓名,以輸入負數或大於100為結束輸入

#include<stdio.h>

intmain()
{
charstuname[100][50],tempname[50];//student'sname
intstuscore[100],tempscore;//student'sscore
intstucount=1;//studentnumber
while(1)
{
printf("請輸入第%d個學生的姓名:",stucount);
scanf("%s",stuname[stucount]);
printf("請輸入第%d個學生的成績:",stucount);
scanf("%d",&stuscore[stucount]);
if(stuscore[stucount]<0||stuscore[stucount]>100)
{
stucount-=1;
break;
}
stucount+=1;
}
inti,j;//loopvariable
for(i=1;i<=stucount;i++)
{
for(j=1;j<=stucount-1;j++)
{
if(stuscore[j]<stuscore[j+1])
{
strcpy(tempname,stuname[j]);
tempscore=stuscore[j];
strcpy(stuname[j],stuname[j+1]);
strcpy(stuname[j+1],tempname);
stuscore[j]=stuscore[j+1];
stuscore[j+1]=tempscore;
}
}
}
printf("成績表 ");
printf("名次 姓名 成績 ");
printf("============================================= ");
for(i=1;i<=stucount;i++)
printf("%d %s %d ",i,stuname[i],stuscore[i]);
printf("============================================= ");
return0;
}

⑻ C語言編程:輸入五個人的名字和成績,根據成績從小到大排序輸出名字和成績,和總成績

又是這個問題
#include<stdio.h>
#include<stdlib.h>

#defineN5
structstudent
{
charname[10];
floatscore;
};

intmain()
{
studentstu[N];
floatsum=0.0;
floatt_score[N];
inti;
intj;
floattemp;

printf("輸入學生名字成績,例如:小明90 ");
for(i=0;i<N;++i)
{
scanf("%s",stu[i].name);
scanf("%f",&stu[i].score);
t_score[i]=stu[i].score;
sum+=stu[i].score;
}

for(i=0;i<N-1;++i)
{
for(j=i+1;j<N;++j)
{
if(t_score[i]>t_score[j])
{
temp=t_score[i];
t_score[i]=t_score[j];
t_score[j]=temp;
}
}
}

printf("按成績從小到大排序: ");
for(i=0;i<N;++i)
{
for(j=0;j<N;++j)
{
if(t_score[i]==stu[j].score)
{
printf("%s%0.2f ",stu[j].name,stu[j].score);
}
}
}
printf("成績總和:%0.2f ",sum);
return0;
}