当前位置:网站首页>[C语言]用结构体把平均分和低于等于平均分的学生数据输出
[C语言]用结构体把平均分和低于等于平均分的学生数据输出
2022-06-11 17:59:00 【跳舞的皮埃尔】
1、题目
学生的记录由姓名和成绩组成,在主函数中输入4名学生的数据,请编写函数计算返回平均分输出,并把低于等于平均分的学生数据通过结构体指针保存输出。
要求:
- 使用结构体:
typedef struct Student
{
char name[20];
int score;
}Stu;
- 使用子函数:float StructAvg(Stu *a,Stu *b,int n,int *m)
- 要在主函数中输出。
输入格式: 依次输入4名学生的姓名和分数
输出格式: 把低于等于平均分的学生数据保存输出
样例:
输入:
KOBE 90
YAO 90
HC 80
JAMES 70
输出:
Avg=82.5
HC 80
JAMES 70
2、完整代码
#include <stdio.h>
#define N 4
typedef struct Student {
char name[20];
int score;
}Stu;
float StructAvg(Stu* a, Stu* b, int n, int* m)
{
int i, j = 0, sum = 0;
float avg;
for (i = 0; i < n; i++)
sum += a[i].score;
avg = sum * 1.0 / n;
for (i = 0; i < n; i++)
if (a[i].score < avg)
b[j++] = a[i];
*m = j;
return avg;
}
int main()
{
int i, j, n;
float ave;
struct Student s[N];
for (i = 0; i < N; i++) {
scanf("%s %d", s[i].name, &s[i].score);
}
struct Student h[N];
ave = StructAvg(s, h, N, &n);
printf("Avg=%.1f\n", ave);
for (i = 0; i < n; i++)
printf("%s %d\n", h[i].name, h[i].score);
printf("\n");
}
3、截图

边栏推荐
- New work of "the father of LSTM": a new method towards self correcting neural network
- Database lock and transaction isolation level
- NR LDPC 打孔-punctured
- Spring 2021 daily question [week6 not finished]
- LeetCode_前缀树_中等_208. 实现 Trie (前缀树)
- EditText 金额限制
- ISCSI详解(四)——ISCSI服务端配置实战
- mysql8安装,navicat安装,sqli-labs搭建
- Ctfhub SQL Boolean blind annotation
- Experiment 3: design and verify all operations represented by linear table sequence on the computer
猜你喜欢
![Acwing game 40 [End]](/img/6b/a9ea5e1f9578d21219c69571e8b0f8.jpg)
Acwing game 40 [End]

社会工程学实战入门

The tle6389 step-down DC-DC switch controller has high efficiency in the whole load range of 1mA to 2.5A - keshijin mall

Line up to pick up the express. At this meeting, I sorted out all kinds of code sets

NFT platform development NFT mall source code NFT mall development chain game development

Introduction to social engineering practice
![[piecemeal knowledge] [network composition] the mobile phone can be connected to the campus network, but the computer can't](/img/a1/7858a0651ddca0dfd187dc128b2036.jpg)
[piecemeal knowledge] [network composition] the mobile phone can be connected to the campus network, but the computer can't

ctfhub-sql布尔盲注

夜神安装apk,以及bp代理

Initial experience of MariaDB spider sharding engine
随机推荐
Intelligent overall legend, legend of wiring, security, radio conference, television, building, fire protection and electrical diagram [transferred from wechat official account weak current classroom]
Ffmpeg parity field frame interlace progressive command and code processing
LDPC 7 - 解码简单例子
[Golang]力扣Leetcode - 349. 两个数组的交集(哈希表)
Secret comment-----
Getting started with Wireshark
jsfinder,wafw00f安装,nmap配置(缺少msvcr120.dll文件)
vulhub
Is it good or not to open a stock account on the flush? Is it safe?
6-2 reverse output of multiple integers recursion
Spring 2021 daily question [week6 not finished]
Why is the UDP stream set to 1316 bytes
网络和并发编程常见面试题
Hello go (XV). Go language common standard library V
Implementation of servlet file upload function (Commons fileUpload)
Codeworks round 481 (Div. 3) [done]
Rtsp/onvif protocol easynvr video platform arm version cross compilation process and common error handling
Three steps of ffmpeg CBR precise bitstream control
在同花顺上面开股票账户好不好,安不安全?
Expérience initiale du moteur de segmentation de l'araignée mariadb