当前位置:首页 » 编程语言 » c语言输入名字和几门成绩
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言输入名字和几门成绩

发布时间: 2022-07-20 10:41:07

c语言中如何用多维数组实现输入一个班30名学生的姓名,学号和5门成绩

#include "stdio.h"
#define N 100
void main()
{
char stu_name[N][20]={""};
char stu_id[N][10]={""};
float stu_score[N][5]={0.0};
int stu_num=0;
int i,j;
printf("Please input the number of class:n=");
scanf("%d",&stu_num);
printf("Please input student's information:\n");
for(i=0;i<stu_num;i++)
{
printf("请输入第%d位学生信息:\n",i+1);
printf("Please input Name:");
getchar();
gets(stu_name[i]);
printf("Please input ID:");
getchar();
gets(stu_id[i]);
for(j=0;j<5;j++)
{

printf("请输入第%d门成绩:",j+1);
scanf("%f",&stu_score[i][j]);
}
}
}

⑵ c语言输入学生人数及课程的门数,输入学生的姓名和相应课程的成绩

#include
struct Student
{
int num;
char name[20];
float score[3], average;
};
int main(void)
{
int i, j;
struct Student std[10] = {0}, temp;
puts("Please enter information of student : ");
for (i = 0; i < 10; ++i)
{
scanf("%d%s", &std[i].num, std[i].name);
for (j = 0; j < 3; ++j)
{
scanf("%f", &std[i].score[j]);
std[i].average += std[i].score[j];
}
std[i].average /= 3;
}
for (i = 0; i < 9; ++i)
{
for (j = 0; j < 9 - i; ++j)
{
if (std[j].average < std[j + 1].average)
{
temp = std[j];
std[j] = std[j + 1];
std[j + 1] = temp;
}
}
}
for (i = 0; i < 10; ++i)
{
printf("Num=%d Name=%-6s ", std[i].num, std[i].name);
printf("Score1=%0.2f Score2=%0.2f Score3=%0.2f ", std[i].score[0], std[i].score[1], std[i].score[2]);
printf("Average=%0.2f\n", std[i].average);
}
return 0;
}

⑶ 用C语言做 输入几个同学的姓名、学号、三门功课成绩,写入到磁盘文件中(文件名自定)

#include <stdio.h>
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 %d %d %d",std.nm,&std.id,&std.a,&std.b,&std.c);
fwrite(std,sizeof(struct student),1,fp);
printf("\nNext:[y/n]");
scanf("%c",ch);
}while(ch!='n'&&ch!='N');

}
else printf("The file cannot be openned!");

fclose(fp);
}

⑷ 使用C语言编程,输入学生的学号,姓名,三门成绩,并求学生、课程的平均成绩。跪求高手速答,三十分钟内

咨询记录 · 回答于2021-10-17

⑸ 用c语言编写程序,要求输入输出三门课程名称和成绩 实在不会做,拜托大神了555

方法一:用数组实现。

#include <stdio.h>

int main( )

{

int i;

char cn[3][20];//3门课名称

int cs[3];//3门课成绩

printf("分别输入3门课的名称 成绩: ");

for(i=0;i<3;i++)

scanf("%s%d",cn[i],&cs[i]);

printf("输出: ");

for(i=0;i<3;i++)

printf("%s %d ",cn[i],cs[i]);

return 1;

}

方法二:把数组改成结构体

#include <stdio.h>

typedef struct cInfo

{

char cn[20];//3门课名称

int cs;//3门课成绩

}CIFO;

int main( )

{

int i;

CIFO cifos[3];

printf("分别输入3门课的名称 成绩: ");

for(i=0;i<3;i++)

scanf("%s%d",cifos[i].cn,&cifos[i].cs);

printf("输出: ");

for(i=0;i<3;i++)

printf("%s %d ",cifos[i].cn,cifos[i].cs);

return 1;

}

⑹ C语言。输入n个学生的姓名,语文,数学,英语成绩,

#include <stdio.h>

float average;

}stu[N],temp;

void main()

printf("请依次输入%d个学生的姓名、语文成绩、数学成绩、英语成绩: ",N);

scanf("%s%d%d%d",&stu[i].name,&stu[i].yuwen,&stu[i].shuxue,&stu[i].yingyu);

stu[i].average=(stu[i].yuwen+stu[i].shuxue+stu[i].yingyu)/3.0;

printf(" 姓名 语文 数学 英语 平均分 ");

for(i=0;i<N;i++)

简介

C语言是一门面向过程的计算机编程语言,与C++、C#、Java等面向对象编程语言有所不同。C语言的设计目标是提供一种能以简易的方式编译、处理低级存储器、仅产生少量的机器码以及不需要任何运行环境支持便能运行的编程语言。C语言描述问题比汇编语言迅速、工作量小、可读性好、易于调试、修改和移植,而代码质量与汇编语言相当。

⑺ C语言在键盘上输入三个学生的信息(包含学号,姓名,三门课的成绩)并在显示器上输

id, name, &m1

id, name, m1

voidprintScore(intscore[4][3])

{inti,j;for(i=0;i<4;i++)

{printf("学生%d的三门成绩分别为:

",i+1);for(j=0;j<3;j++)

{printf("%d ",score<i>[j]);

if(j==2)printf(" ");}}printf(" ");}

printf()函数是格式化输出函数,一般用于向标准输出设备按规定格式输出信息。格式输出,它是c语言中产生格式化输出的函数(在stdio.h中定义)。

函数介绍

printf()函数是格式化输出函数,一般用于向标准输出设备按规定格式输出信息。在编写程序时经常会用到此函数。函数的原型为:intprintf(constchar*format);

函数返回值为整型。若成功则返回输出的字符数,输出出错则返回负值。

printf()函数的调用格式为:printf("<格式化字符串>",<参量表>);其中格式化字符串包括两部分内容:一部分是正常字符,这些字符将按原样输出;另一部分是格式化规定字符,以"%"开始,后跟一个或几个规定字符,用来确定输出内容格式。

以上内容参考:网络-printf()

⑻ C语言 键盘输入4个学生姓名以及每个学生3门课的成绩。

有点小复杂哦

请看下面的代码


#include<stdio.h>
#include<string.h>

/*常量字符串默认长度*/
constintSTRING_DEFAULT_LEN=50;
/*常量学生人数4人*/
constintSTUDENTS_COUNT=4;
/*常量课程数量3门*/
constintCOURSE_COUNT=3;

/*变量选课记录*/
intsign_up_of_course_count;

/*课程数据结构*/
structcourse{
charname[STRING_DEFAULT_LEN];
};

/*学生数据结构*/
structstudent{
charname[STRING_DEFAULT_LEN];
};

/*学生的选课数据结构,包括学生/课程/得分*/
structsign_up_of_course{
structstudents;
structcoursec;
floatscore;
};


/*子函数输出每个学生的平均分*/
voidprint_avg_of_each_student(conststructsign_up_of_course*,int);
/*子函数输出每门课的平均分*/
voidprint_avg_of_each_course(conststructsign_up_of_course*,int);
/*子函数找出最高分对应的学生和课程*/
voidprint_max_score_info(conststructsign_up_of_course*,int);

intmain()
{
/*初始化4个学生*/
structstudents[STUDENTS_COUNT]={"StudentA","StudentB","StudentC","StudentD"};

/*初始化3门课程*/
structcoursec[COURSE_COUNT]={"Course1","Course2","Course3"};

/*初始化选课记录*/
sign_up_of_course_count=STUDENTS_COUNT*COURSE_COUNT;
structsign_up_of_course*signup=newstructsign_up_of_course[sign_up_of_course_count];
memset(signup,0,sign_up_of_course_count*sizeof(structsign_up_of_course));

inti,j;
for(i=0;i<STUDENTS_COUNT;i++)
{
for(j=0;j<COURSE_COUNT;j++)
{
/*学生和课程数据到该选课记录*/
memcpy(&((signup+i*(STUDENTS_COUNT-1)+j)->s),&s[i],sizeof(structstudent));
memcpy(&((signup+i*(STUDENTS_COUNT-1)+j)->c),&c[j],sizeof(structcourse));
}
}

/*请用户输入每个选课记录的成绩,即各个学生的成绩*/
intk=0;
for(k=0;k<sign_up_of_course_count;k++)
{
/*用户输入成绩,保存到选择记录的分数栏中*/
printf("请输入学生%s的课程%s的成绩:",((signup+k)->s).name,((signup+k)->c).name);
scanf("%d",&((signup+k)->score));
}

/*调用子函数输出每个学生的平均分*/
print_avg_of_each_student(signup,sign_up_of_course_count);

/*调用子函数输出每门课的平均分*/
print_avg_of_each_course(signup,sign_up_of_course_count);

/*调用子函数找出最高分对应的学生和课程*/
print_max_score_info(signup,sign_up_of_course_count);

/*销毁分配的内存*/
delete[]signup;

getchar();
getchar();
return0;
}

/*实现子函数输出每个学生的平均分*/
voidprint_avg_of_each_student(conststructsign_up_of_course*signup,intlen)
{
structstudent_score
{
structstudents; /*学生*/
floatavg; /*平均值*/
floattotal; /*总分*/
intcount; /*计数*/
};

structstudent_scorescores[STUDENTS_COUNT];
memset(scores,0,STUDENTS_COUNT*sizeof(structstudent_score));

inti,j;
chars1[STRING_DEFAULT_LEN];
chars2[STRING_DEFAULT_LEN];
intscores_filled_pos=-1;
boolscores_record_proessed=false;
/*处理每一条选课记录,按学生合计*/
for(i=0;i<len;i++)
{
memset(s1,0,STRING_DEFAULT_LEN);
memset(s2,0,STRING_DEFAULT_LEN);

/*求学生的分数合计*/
scores_record_proessed=false;
for(j=0;j<STUDENTS_COUNT;j++)
{
strcpy(s1,signup[i].s.name);
strcpy(s2,scores[j].s.name);

if(strcmp(s1,s2)==0)
{
memcpy(&scores[j].s,&signup[i].s,sizeof(structstudent));
scores[j].total+=signup[i].score;
scores[j].count+=1;

scores_record_proessed=true;

continue;
}
}

if(scores_record_proessed==false)
{
scores_filled_pos+=1;
memcpy(&scores[scores_filled_pos].s,&signup[i].s,sizeof(structstudent));
scores[scores_filled_pos].total+=signup[i].score;
scores[scores_filled_pos].count+=1;
continue;
}
}

/*求平均值并输出*/
for(j=0;j<STUDENTS_COUNT;j++)
{
scores[j].avg=scores[j].total/scores[j].count;
printf("学生%s的平均分数是%2.2f ",scores[j].s.name,scores[j].avg);
}

}

/*实现子函数输出每门课的平均分*/
voidprint_avg_of_each_course(conststructsign_up_of_course*signup,intlen)
{
structcourse_score
{
structcoursec; /*课程*/
floatavg; /*平均值*/
floattotal; /*总分*/
intcount; /*计数*/
};

structcourse_scorescores[COURSE_COUNT];
memset(scores,0,COURSE_COUNT*sizeof(structcourse_score));

inti,j;
chars1[STRING_DEFAULT_LEN];
chars2[STRING_DEFAULT_LEN];
intscores_filled_pos=-1;
boolscores_record_proessed=false;
/*处理每一条选课记录,按课程合计*/
for(i=0;i<len;i++)
{
memset(s1,0,STRING_DEFAULT_LEN);
memset(s2,0,STRING_DEFAULT_LEN);

/*求学生的分数合计*/
scores_record_proessed=false;
for(j=0;j<COURSE_COUNT;j++)
{
strcpy(s1,signup[i].c.name);
strcpy(s2,scores[j].c.name);

if(strcmp(s1,s2)==0)
{
memcpy(&scores[j].c,&signup[i].c,sizeof(structcourse));
scores[j].total+=signup[i].score;
scores[j].count+=1;

scores_record_proessed=true;

continue;
}
}

if(scores_record_proessed==false)
{
scores_filled_pos+=1;
memcpy(&scores[scores_filled_pos].c,&signup[i].c,sizeof(structstudent));
scores[scores_filled_pos].total+=signup[i].score;
scores[scores_filled_pos].count+=1;
continue;
}
}

/*求平均值并输出*/
for(j=0;j<COURSE_COUNT;j++)
{
scores[j].avg=scores[j].total/scores[j].count;
printf("课程%s的平均分数是%2.2f ",scores[j].c.name,scores[j].avg);
}
}

/*实现子函数找出最高分对应的学生和课程*/
voidprint_max_score_info(conststructsign_up_of_course*signup,intlen)
{
/*最多的并列最高分的学生数,即学生总数*/
constintMAX_COUNT=STUDENTS_COUNT*COURSE_COUNT;

/*存储最高分信息的数组,可存储多个并列最高分*/
structsign_up_of_coursemax_course_signup[MAX_COUNT];
/*并列最高分个数*/
intcount=0;
inti;

for(i=0;i<len;i++)
{
/*处理第一件时,尚无比较对象,作为最高分的初始值*/
if(i==0)
{
count++;
memcpy(max_course_signup,signup,sizeof(structsign_up_of_course));

continue;
}

/*发现更高的分数时,并列最高分个数将降为1*/
if(max_course_signup[count-1].score<(signup+i)->score)
{
count=1;
memcpy(&max_course_signup[count-1],signup+i,sizeof(structsign_up_of_course));
}

/*发现并列最高分时,存储数组个数自增1*/
if(max_course_signup[count-1].score==(signup+i)->score)
{
count++;
memcpy(&max_course_signup[count-1],signup+i,sizeof(structsign_up_of_course));
}
}

/*输出最高分*/
for(i=0;i<count-1;i++)
{
printf("最高分的学生是%s,课程为:%s。 ",max_course_signup[i].s.name,max_course_signup[i].c.name);
}
}

⑼ C语言综合问题:输入5个学生的姓名、学号和5门课成绩计算每个学生的总分和平均分并按从高到低排序

定义一个结构体
struct student
{
char *name;//姓名
int num[10];//学号
int scor[5];//5门课成绩
int average;//平均成绩
};
用student定义5个变量,再操作应该就很简单了