用c语言编写 输入N位同学的姓名(姓名的长度最长的不大于19),及成绩,找出第一名同学,并显示其姓

作者&投稿:葛彦 (若有异议请与网页底部的电邮联系)
C语言编程输入n位同学的姓名(姓名的长度最长的不大于19)及成绩,找出第一名同学,并打印其姓名及成绩。~

#include
#define N 3 //定义有多少名学生
struct student
{
char name[19];
double score;
}stu[N];
void main()
{
int i,first;
double max=0.0;
for(i=0;i<N;i++)
{
scanf("%s%lf",&stu[i].name,&stu[i].score);//输入每一名学生的姓名、成绩
if(stu[i].score>max)
{
max=stu[i].score;//求出最高成绩
first=i;//求出成绩最高的那名学生对应的索引
}
}
printf("第一名为:%s %g
",stu[first].name,stu[first].score);
}

#include#include#define N 10struct student{char name[20];int score;};void main(){struct student stu[N];struct student *p; int i,v,s,temp;char tempname1[20],tempname2[20];for(i=0;iname,p->score);}

#include <stdio.h>
#define N 3 //定义有多少名学生
struct student
{
char name[19];
double score;
}stu[N];
void main()
{
int i,first;
double max=0.0;
for(i=0;i<N;i++)
{
scanf("%s%lf",&stu[i].name,&stu[i].score);//输入每一名学生的姓名、成绩
if(stu[i].score>max)
{
max=stu[i].score;//求出最高成绩
first=i;//求出成绩最高的那名学生对应的索引
}
}
printf("第一名为:%s %g\n",stu[first].name,stu[first].score);
}

#include<stdio.h>
#include<string.h>
typedef struct stu_grade
{
char name[20];
int score;
} stu_g;

int main()
{
stu_g grade_stu[20];
int i = 0,max,bast_grade,all;
for ( i = 0; i < 20; i++)
{
scanf("%s",grade_stu[i].name);
getchar();
scanf("%d",&grade_stu[i].score);
getchar();
if (strcmp(grade_stu[i].name,"0") == 0)
if (grade_stu[i].score == 0)
{
all = i;
break;
}
}
max = grade_stu[0].score;
bast_grade = 0;
for (i = 0; i < all; i++)
{
if ( max < grade_stu[i].score) bast_grade = i;
}
printf("最好的是%s,成绩是%d
",grade_stu[bast_grade].name,grade_stu[bast_grade].score);
return 0;
}

比较简单点的方法




东营区15848027091: 用c语言编写 输入N位同学的姓名(姓名的长度最长的不大于19),及成绩,找出第一名同学,并显示其姓 -
寸国合比: #include <stdio.h>#define N 3 //定义有多少名学生 struct student { char name[19]; double score; }stu[N]; void main() { int i,first; double max=0.0; for(i=0;i<N;i++) { scanf("%s%lf",&stu[i].name,&stu[i].score);//输入每一名学生的姓名、成绩 if(stu[i]....

东营区15848027091: /编写一个程序,输入n个学生的姓名和出生日期,并按年龄从大到小输出.(用c语言编写) #include<stdio.h> # -
寸国合比: #include<stdio.h> int main() {int n,i,j,index;struct std{char name[10];int day; }student[10],s;printf("请输入n,n<=10\n");scanf("%d",&n);for(i=0;i<n;i++){printf("请输入名字和出生日期");scanf("%s%d",student[i].name,&student[i]...

东营区15848027091: 用c语言编写程序,定义字符数组,输入n个学生姓名,,首先对数组元素进行排序,再查找某人是否在数组中, -
寸国合比: 对汉字排序要转成拼音

东营区15848027091: C语言,数组.用键盘输入n个学生的姓名,并按字典顺序排序输出,n值由键盘输入. -
寸国合比: #include <stdio.h> #include<string.h> int main () {int n,i,j; char s[100][20],t[20]; scanf("%d",&n); for(i=0;i<n;i++) scanf("%s",s[i]); for(i=0;i<n-1;i++) for(j=0;j<n-1-i;j++) if(strcmp(s[j],s[j+1])>0) {strcpy(t,s[j]); strcpy(s[j],s[j+1]); strcpy(s[j+1],t); } printf("\n\...

东营区15848027091: 用C语言写..求帮忙 有n个学生,每个学生的数据包括姓名、3门课程(高数、物理、C语言)的成绩.首 -
寸国合比: 第一个问题不难写啊,写一个结构体,new一个数组,往里面输入数据就好了,然后输出的时候在求一下平均第二个整个链表进栈再出栈整个顺序不就逆置了...

东营区15848027091: C语言.输入n个学生的姓名,语文,数学,英语成绩, -
寸国合比: #include <stdio.h>#define N 5 struct student { char name[20]; int yuwen,shuxue,yingyu; float average; }stu[N],temp; void main() { int i,j; printf("请依次输入%d个学生的姓名、语文成绩、数学成绩、英语成绩:\n",N); for(i=0;i<N;i++) { printf("第%d...

东营区15848027091: C语言,输入n个学生信息存入文件,输出优秀,请挖错 -
寸国合比: 可能是Win TC的一个bug,可以这样试试: float sc; for(i=0; i { scanf("%ld%s%f",&p[i].num,p[i].name,&sc); p[i].score = sc; }

东营区15848027091: 用C语言做 输入几个同学的姓名、学号、三门功课成绩,写入到磁盘文件中(文件名自定) -
寸国合比: #include main() { FILE *fp; char ch,*fn; stuct student{ char *nm;int id,a,b,c; }std; printf("Please input a file name:\n"); gets(fn); if(fp=fopen(fn,"a+")){ do { printf("\nPlease input a student's name,id,score a,score b,score c\n"); scanf("%s %d %d...

东营区15848027091: 编写一个程序,输入n个学生的姓名和出生日期,并按年龄从大到小输出.(用c语言编写) -
寸国合比: 定义一个数组的数据结构,然后输入数据,经冒泡发排序之后输出,思想是这样,程序就不写出来了

东营区15848027091: c语言编程:有n个同学的数据包括序号(num),姓名(name[20]),性别(sex),年龄(a -
寸国合比: 简单一点的代码 #include #include typedef struct stu { int num; char name[20]; char sex[10]; int age; int score[3]; }stu; int main() { stu *data; int *total; float *ave; int n; int i; printf("input total students number\n"); scanf("%d", &n); if(n <= 0) { printf(...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网