当前位置:   article > 正文

4.1已知四个学生的记录信息,(包括学号,姓名,成绩,)要求输出成绩最高者_有4个学生的信息如下,包括学号、姓名,性别、年龄、语文成绩、数学成绩和英语成绩

有4个学生的信息如下,包括学号、姓名,性别、年龄、语文成绩、数学成绩和英语成绩

4.1已知四个学生的记录信息,(包括学号,姓名,成绩,)要求输出成绩最高者

  1. #include <stdio.h>//已知四个学生的记录信息,(包括学号,姓名,成绩,)要求输出成绩最高者
  2. struct stu{
  3. char sno[10];
  4. char name[10];
  5. int score;
  6. }student[5]={
  7. {"101","sss",45},
  8. {"102", "Zhang ping", 62.5},
  9. {"103", "He fang", 92.5},
  10. {"104", "Cheng ling", 87},
  11. {"105", "Wang ming",58},
  12. };
  13. int main() {
  14. struct stu p;
  15. int max=0;
  16. for (int i = 0; i <5; ++i) {
  17. if(student[i].score>max){
  18. max=student[i].score;
  19. p=student[i];
  20. }
  21. printf("%s %s %d",student[i].sno,student[i].name,student[i].score);
  22. printf("\n");
  23. }
  24. printf("the highest is %s %s %d",p.sno,p.name,p.score); return 0;
  25. }

 编写output()函数输入,输出5个学生的成绩记录,每个记录包括学号,姓名性别,年龄5门口成绩

  1. #include <stdio.h>//
  2. struct stu{
  3. char sno[10];
  4. char name[10];
  5. char sex[10];
  6. int age;
  7. int score[5];
  8. }student[5]={
  9. // {"101","sss","man",45,{90,90,21,34,56}},
  10. // {"102","gg","woman",45,{90,80,51,94,66}},
  11. };//
  12. void outupt(struct stu student[],int n) {
  13. for (int i = 0; i < n; ++i) {
  14. printf("%s %s %s ", student[i].sno, student[i].name, student[i].sex);
  15. for (int j = 0; j <n ; ++j) {
  16. printf("%d ",student[i].score[j]);
  17. }
  18. printf("\n");
  19. }
  20. }
  21. int main() {
  22. struct stu p;
  23. int n= sizeof(student)/ sizeof(student[0]);
  24. printf("n=%d",n);
  25. for (int i = 0; i <n; ++i) {
  26. printf("input sno name sex age:\n");
  27. scanf("%s %s %s %d",student[i].sno, student[i].name, student[i].sex,&student[i].age);
  28. printf("input score:\n");
  29. for (int j = 0; j <5; ++j) {
  30. scanf("%d", &student[i].score[j]);
  31. }
  32. printf("\n");
  33. }
  34. outupt(student,n);
  35. return 0;
  36. }

 

 

有10个学生,每个学生学习三门功课,计算每个人的平均成绩和总的不及格人数

  1. #include <stdio.h>//有10个学生,每个学生学习三门功课,计算每个人的平均成绩和总的不及格人数
  2. struct stu{
  3. char sno[10];
  4. int score[3];
  5. }student[5]={
  6. {"107",{13,90,21}},
  7. {"105",{20,90,21}},
  8. {"103",{50,90,21}},
  9. {"104",{10,90,21}},
  10. {"102",{100,100,100}},
  11. };//
  12. int main() {
  13. int nopass=0;//定义不及格人数
  14. double sum=0;
  15. double ave=0.0;
  16. for (int i = 0; i < 5; ++i) {
  17. if(student[i].score[0]<60||student[i].score[1]<60||student[i].score[2]<60){
  18. nopass++;
  19. }
  20. sum=0;
  21. ave=0.0;
  22. for (int j = 0; j <3; ++j) {
  23. sum=student[i].score[j]+sum;
  24. printf("sum=%.2f ",sum);
  25. }
  26. ave=sum/3.0;
  27. printf("%s aver is %.1f\n",student[i].sno,ave);
  28. }
  29. printf("no pass people is %d",nopass);
  30. return 0;
  31. }

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/1000954
推荐阅读
相关标签
  

闽ICP备14008679号