⑴ 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;
}