赞
踩
4.1已知四个学生的记录信息,(包括学号,姓名,成绩,)要求输出成绩最高者
- #include <stdio.h>//已知四个学生的记录信息,(包括学号,姓名,成绩,)要求输出成绩最高者
- struct stu{
- char sno[10];
- char name[10];
- int score;
- }student[5]={
- {"101","sss",45},
- {"102", "Zhang ping", 62.5},
- {"103", "He fang", 92.5},
- {"104", "Cheng ling", 87},
- {"105", "Wang ming",58},
-
- };
- int main() {
- struct stu p;
- int max=0;
- for (int i = 0; i <5; ++i) {
- if(student[i].score>max){
- max=student[i].score;
- p=student[i];
- }
-
- printf("%s %s %d",student[i].sno,student[i].name,student[i].score);
- printf("\n");
- }
- printf("the highest is %s %s %d",p.sno,p.name,p.score); return 0;
- }
编写output()函数输入,输出5个学生的成绩记录,每个记录包括学号,姓名性别,年龄5门口成绩
- #include <stdio.h>//
- struct stu{
- char sno[10];
- char name[10];
- char sex[10];
- int age;
- int score[5];
- }student[5]={
- // {"101","sss","man",45,{90,90,21,34,56}},
- // {"102","gg","woman",45,{90,80,51,94,66}},
- };//
- void outupt(struct stu student[],int n) {
- for (int i = 0; i < n; ++i) {
- printf("%s %s %s ", student[i].sno, student[i].name, student[i].sex);
- for (int j = 0; j <n ; ++j) {
- printf("%d ",student[i].score[j]);
- }
- printf("\n");
- }
- }
- int main() {
- struct stu p;
- int n= sizeof(student)/ sizeof(student[0]);
- printf("n=%d",n);
- for (int i = 0; i <n; ++i) {
- printf("input sno name sex age:\n");
- scanf("%s %s %s %d",student[i].sno, student[i].name, student[i].sex,&student[i].age);
- printf("input score:\n");
- for (int j = 0; j <5; ++j) {
- scanf("%d", &student[i].score[j]);
- }
- printf("\n");
- }
- outupt(student,n);
- return 0;
- }
- #include <stdio.h>//有10个学生,每个学生学习三门功课,计算每个人的平均成绩和总的不及格人数
- struct stu{
- char sno[10];
- int score[3];
- }student[5]={
- {"107",{13,90,21}},
- {"105",{20,90,21}},
- {"103",{50,90,21}},
- {"104",{10,90,21}},
- {"102",{100,100,100}},
- };//
- int main() {
- int nopass=0;//定义不及格人数
- double sum=0;
- double ave=0.0;
- for (int i = 0; i < 5; ++i) {
- if(student[i].score[0]<60||student[i].score[1]<60||student[i].score[2]<60){
- nopass++;
- }
- sum=0;
- ave=0.0;
- for (int j = 0; j <3; ++j) {
- sum=student[i].score[j]+sum;
- printf("sum=%.2f ",sum);
- }
- ave=sum/3.0;
- printf("%s aver is %.1f\n",student[i].sno,ave);
- }
- printf("no pass people is %d",nopass);
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。