有10个学生,每个学生的数据包括学号、姓名、3门课程的成绩,从键盘输入10个学生数据,要求输出3门课程总平均成绩,以及最高分的学生的数据(包括学号、姓名、3门课程成绩、平均分数)。
有10个学生,每个学生的数据包括学号、姓名、3门课程的成绩,从键盘输入10个学生数据,要求输出3门课程总平均成绩,以及最高分的学生的数据(包括学号、姓名、3门课程成绩、平均分数)。
方法一:
#include <stdio.h>
#include <stdlib.h>struct Student
{int num;char name[10];float score[3];float aver;
};void input(struct Student* st);
void print(struct Student* st);int main()
{struct Student* stu = (struct Student*)malloc(10 * sizeof(struct Student));input(stu);print(stu);return 0;
}void input(struct Student* st)
{ int i=0;for(i=0;i<10;++i){printf("Please enter No.%d student's num name score:", i + 1);scanf("%d %s", &st[i].num, st[i].name);int j=0;for (j = 0; j < 3; j++){scanf("%f", &st[i].score[j]);}}}void print(struct Student* st)
{int i=0, j=0;float sum[10], total = 0, max=0;printf("\n");for (i = 0; i < 10; ++i) {sum[i] = 0;for (j = 0; j < 3; j++){sum[i] += st[i].score[j];//记录第i个学生的三门课的分数总和}printf("The average score of No.%d is %.2f\n", st[i].num, sum[i] / 3);//记录各个学生的学号及三门平均分 total += sum[i];//记录一共10个学生30门课的全部成绩 }printf("Total Average: %.2f\n\n", total / 30.0);//记录一共10个学生30门课的总平均分 for (i = 0; i < 10; i++){if (sum[i] > max || i == 0){max = sum[i];j = i;}}printf("The num and name of the student that achieved the highest scores are:%d %-5s\n", (st + j)->num, (st + j)->name);//记录最高分学生的学号和成绩 printf("His(Her) three scores are:");for (i = 0; i < 3; i++) printf("%.2f ", (st + j)->score[i]);//记录最高分学生的三门课成绩 printf("\n");printf("His(Her) average score of three scores is:%.2f\n", max / 3.0);//记录最高分学生的三门课的平均分
}
在VS2019下,需将源文件的scanf做些修改:
#include <stdio.h>
#include <stdlib.h>struct Student
{int num;char name[10];float score[3];float aver;
};void input(struct Student* st);
void print(struct Student* st);int main()
{struct Student* stu = (struct Student*)malloc(10 * sizeof(struct Student));input(stu);print(stu);return 0;
}void input(struct Student* st)
{int i = 0;for (i = 0; i < 10; ++i){printf("Please enter No.%d student's num name score:", i + 1);scanf_s("%d %s", &st[i].num, st[i].name, (unsigned int)sizeof(st[i].name));int j = 0;for (j = 0; j < 3; j++){scanf_s("%f", &st[i].score[j]);}}}void print(struct Student* st)
{int i = 0, j = 0;float sum[10], total = 0, max = 0;printf("\n");for (i = 0; i < 10; ++i){sum[i] = 0;for (j = 0; j < 3; j++){sum[i] += st[i].score[j];//记录第i个学生的三门课的分数总和}printf("The average score of No.%d is %.2f\n", st[i].num, sum[i] / 3);//记录各个学生的学号及三门平均分 total += sum[i];//记录一共10个学生30门课的全部成绩 }printf("Total Average: %.2f\n\n", total / 30.0);//记录一共10个学生30门课的总平均分 for (i = 0; i < 10; i++){if (sum[i] > max || i == 0){max = sum[i];j = i;}}printf("The num and name of the student that achieved the highest scores are:%d %-5s\n", (st + j)->num, (st + j)->name);//记录最高分学生的学号和成绩 printf("His(Her) three scores are:");for (i = 0; i < 3; i++) printf("%.2f ", (st + j)->score[i]);//记录最高分学生的三门课成绩 printf("\n");printf("His(Her) average score of three scores is:%.2f\n", max / 3.0);//记录最高分学生的三门课的平均分
}
方法二:
#include<stdio.h>#define N 10struct student
{char num[6];char name[8];float score[3];float avr;
}stu[N];int main()
{int i,j,maxi;float sum,max,average;for(i=0;i<N;i++)//i控制学生数量 {printf("input scores of students %d:\n",i+1);printf("NO.:"); scanf("%s",stu[i].num);//输入学号 printf("name:");scanf("%s",stu[i].name);//输入姓名 for(j=0;j<3;j++)//j控制课程数量 {printf("score %d:",j+1);scanf("%f",&stu[i].score[j]);//输入三门课的成绩 }}average=0;max=0;maxi=0;for(i=0;i<N;i++){sum=0;for(j=0;j<3;j++){sum+=stu[i].score[j];//记录第i个学生的三门课的分数总和}stu[i].avr=(float)(sum/3.0) ;//记录各个学生的学号及三门平均分 average+=stu[i].avr;//记录一共10个学生30门课的平均分之和 if(sum>max){max=sum;maxi=i;}}average/=N;//记录一共10个学生30门课的总平均分 printf(" NO. name score1 score2 score3 average\n");for(i=0;i<N;i++) {printf("%5s%10s",stu[i].num,stu[i].name);for(j=0;j<3;j++){printf("%9.2f",stu[i].score[j]);}printf(" %8.2f\n",stu[i].avr);}printf("average=%5.2f\n",average);//记录最高分学生的三门课的平均分printf("The highest score is:student %s,%s\n",stu[maxi].num,stu[maxi].name);//记录最高分学生的学号和成绩 printf("his scores are:%6.2f,%6.2f,%6.2f,average:%5.2f.\n",stu[maxi].score[0],stu[maxi].score[1],stu[maxi].score[2],stu[maxi].avr);//记录最高分学生的三门课成绩return 0;
}
在VS2019下,需将源文件的scanf做些修改:
#include <stdio.h>
#include <stdlib.h>struct Student
{int num;char name[10];float score[3];float aver;
};void input(struct Student* st);
void print(struct Student* st);int main()
{struct Student* stu = (struct Student*)malloc(10 * sizeof(struct Student));input(stu);print(stu);return 0;
}void input(struct Student* st)
{int i = 0;for (i = 0; i < 10; ++i){printf("Please enter No.%d student's num name score:", i + 1);scanf_s("%d %s", &st[i].num, st[i].name, (unsigned int)sizeof(st[i].name));int j = 0;for (j = 0; j < 3; j++){scanf_s("%f", &st[i].score[j]);}}}void print(struct Student* st)
{int i = 0, j = 0;float sum[10], total = 0, max = 0;printf("\n");for (i = 0; i < 10; ++i){sum[i] = 0;for (j = 0; j < 3; j++){sum[i] += st[i].score[j];//记录第i个学生的三门课的分数总和}printf("The average score of No.%d is %.2f\n", st[i].num, sum[i] / 3);//记录各个学生的学号及三门平均分 total += sum[i];//记录一共10个学生30门课的全部成绩 }printf("Total Average: %.2f\n\n", total / 30.0);//记录一共10个学生30门课的总平均分 for (i = 0; i < 10; i++){if (sum[i] > max || i == 0){max = sum[i];j = i;}}printf("The num and name of the student that achieved the highest scores are:%d %-5s\n", (st + j)->num, (st + j)->name);//记录最高分学生的学号和成绩 printf("His(Her) three scores are:");for (i = 0; i < 3; i++) printf("%.2f ", (st + j)->score[i]);//记录最高分学生的三门课成绩 printf("\n");printf("His(Her) average score of three scores is:%.2f\n", max / 3.0);//记录最高分学生的三门课的平均分
}
有10个学生,每个学生的数据包括学号、姓名、3门课程的成绩,从键盘输入10个学生数据,要求输出3门课程总平均成绩,以及最高分的学生的数据(包括学号、姓名、3门课程成绩、平均分数)。相关推荐
- (C语言)有10个学生,每个学生的数据包括学号,姓名,3门课程的成绩,从键盘输入10个学生数据,要求输出3门课程总平均成绩,以及最高分的学生的数据(包括学号,姓名,3门课程成绩,平均分数)
有10个学生,每个学生的数据包括学号,姓名,3门课程的成绩,从键盘输入10个学生数据,要求输出3门课程总平均成绩,以及最高分的学生的数据(包括学号,姓名,3门课程成绩,平均分数) #define _C ...
- PTA 最大和最小 (10 分)请使用指针法(间接访问)编写程序,程序的功能是从键盘输入 10 个数,求其最大值和最小值的差。
请使用指针法(间接访问)编写程序,程序的功能是从键盘输入 10 个数,求其最大值和最小值的差. 输入格式: 输入10个整数 输出格式: 无 输入样例: 1 2 3 4 5 6 7 8 9 10 输出样 ...
- C语言:有十个学生,每个学生的数据包括学号、姓名、3门课程的成绩,从键盘输入10个学生数据,要求输出3门课程的总平均成绩,以及最高分的学生的数据(包括学号、姓名、3门课程成绩、平均分数)
题目:有十个学生,每个学生的数据包括学号.姓名.3门课程的成绩,从键盘输入10个学生数据,要求输出3门课程的总平均成绩,以及最高分的学生的数据(包括学号.姓名.3门课程成绩.平均分数). 根据题目要求 ...
- 有10个学生,每个学生的数据包括学号、姓名、3门课程的成绩,从键盘输入10个学生数据 要求输出3门课程总平均成绩,以及最高分的学生的数据(包括学号、姓名、3门课程成绩)
/*有10个学生,每个学生的数据包括学号.姓名.3门课程的成绩,从键盘输入10个学生数据 要求输出3门课程总平均成绩,以及最高分的学生的数据(包括学号.姓名.3门课程成绩)*/#include < ...
- 习题 9.5 有10个学生,每个学生的数据包括学号、姓名、3门课程的成绩,从键盘输入10个学生数据,要求输出3门课程总平均成绩,以及最高分的学生的数据(包括学号、姓名、3门课程成绩、平均分数)。
C程序设计(第四版) 谭浩强 习题9.5 个人设计 习题 9.5 有10个学生,每个学生的数据包括学号.姓名.3门课程的成绩,从键盘输入10个学生数据,要求输出3门课程总平均成绩,以及最高分的学生的数 ...
- C语言:9.5 有10个学生,每个学生的数据包括学号、姓名、3门课程的成绩,从键盘输入10个学生数据,要求输出3门课程总平均分成绩,以及最高分的学生的数据(包括学号、姓名、3门课程成绩、平均分数)。
//9.5 有10个学生,每个学生的数据包括学号.姓名.3门课程的成绩,从键盘输入10个学生数据, //要求输出3门课程总平均分成绩,以及最高分的学生的数据(包括学号.姓名.3门课程成绩.平均分数). ...
- c语言从键盘输入10个学生的姓名和成绩,C语言:有10个学生,每个学生的数据包括学号、姓名、3门课的成绩,从键盘输入10个学生的数据,...
C语言:有10个学生,每个学生的数据包括学号.姓名.3门课的成绩,从键盘输入10个学生的数据, 答案:2 信息版本:手机版 解决时间 2019-10-06 13:43 已解决 2019-10-06 ...
- 【c语言入门】有10个学生,每个学生的数据包含学号、姓名、3门课的成绩,从键盘输入10个学生的数据,要求打印输出3门课程的总平均成绩。
题目:有10个学生,每个学生的数据包含学号.姓名.3门课的成绩,从键盘输入10个学生的数据,要求打印输出3门课程的总平均成绩. #include <stdio.h> #define N 3 ...
- 从键盘输入10个学生的姓名,再从键盘输入一个姓名,查找这个姓名是否在前面输入的10个姓名之中。
[问题描述] 从键盘输入10个学生的姓名,再从键盘输入一个姓名,查找这个姓名是否在前面输入的10个姓名之中. [输入形式] lst=["范兴贵","吴帅飞",& ...
最新文章
- ORB-SLAM(1) --- 让程序飞起来
- mysql select操作
- SpringMVC运行流程分析
- mysql 结束符报错_【踩坑记录】MySQL 实现自定义递归函数
- COG云原生优化遥感影像,瓦片切分的应用实践
- java 放行文件_springmvc中关于静态资源的放行
- 张高兴的 Windows 10 IoT 开发笔记:部署 ASP.NET Core 2 应用
- JavaScript - 自定义鼠标右键菜单
- Pytorch使用CPU
- 总结SSL/TLS协议运行机制
- 根据计算机配置设置bios,电脑如何进入bios设置
- 微信小程序——比较数字大小案例
- Android kotlin使用id直接做view的引用
- 科研篇一:NeurIPS2019 分类整理-对抗样本Meta-Learning
- Android音乐播放器制作(一)扫描本地音乐显示在手机上
- Hibernate save()与persist()区别
- mysql重新设置主键生成策略为auto_increment时报错:resulting in duplicate entry '1' for key 'PRIMARY'
- 浏览器会不会缓存html,浏览器缓存机制(一)
- Windows10 VS2019编译WebRTC官方demo
- 每个软件工程师都应该知道的有关实时数据的统一概念
热门文章
- 一个毕业一年程序员的感悟
- 网络安全学习篇28_阶段一小结篇_木马的原理及木马防范
- 三行代码解决全部网页木马
- 毕业设计计算机文献翻译,(完整版)计算机类_毕业设计英文文献及翻译_
- gogole-----------拓展工具 . crx 安装失败 解法
- Alcohol 120% v2.0.0 1331 (支援+蓝光+Win7)2010破解中文零售版
- Map创建自定义图片图层,图片会随着地图缩放而缩放,uniapp、高德、腾讯、百度
- 如何跟女朋友解释“W3CShool”之001
- 教你如何切换淘宝镜像
- 如何为自己所有的域名注册Google企业邮箱