当前位置:网站首页>[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、截图

边栏推荐
- Ffmpeg parity field frame interlace progressive command and code processing
- Secret comment-----
- SISO decoder for a general (n,n-1) SPC code(补充章节3)
- Getting started with Wireshark
- 7-1 are prime numbers
- 【无标题】
- 【先收藏,早晚用得到】100个Flink高频面试题系列(二)
- SISO decoder for min sum (supplementary Chapter 2)
- Spring 2021 daily question [week5 not finished]
- Talking about telework | community essay solicitation
猜你喜欢

社会工程学实战入门

Upload labs failed to pass the customs halfway and the middle road collapsed

zabbix怎样自定义mysql监控项并触发告警

LDPC 7 - 解码简单例子
![[untitled]](/img/ab/04beacfc7975cc3c54399447aa5027.png)
[untitled]

ctfhub-sql布尔盲注
![[collect first and use it sooner or later] 100 Flink high-frequency interview questions series (I)](/img/3e/efce1cff81abf395ffc24ac57b05d7.png)
[collect first and use it sooner or later] 100 Flink high-frequency interview questions series (I)

PIL-Pillow图像处理【1】-安装与新建

Understanding of distributed transactions

How to learn and self-study
随机推荐
Ffmpeg parity field frame interlace progressive command and code processing
Ctfhub SQL Boolean blind annotation
SISO decoder for a general (n,n-1) SPC code(补充章节3)
安全领域常规术语
Ffmpeg hard codec inter QSV
Spring 2021 daily question [end of week4]
Why is the UDP stream set to 1316 bytes
Intelligent overall legend, legend of wiring, security, radio conference, television, building, fire protection and electrical diagram [transferred from wechat official account weak current classroom]
Comparison of mongoose in express, KOA and egg
Radiogroup dynamically add RadioButton
如何学习和自学
SISO Decoder for a General (n, N - 1) SPC Code (Supplementary section 3)
mysql8安装,navicat安装,sqli-labs搭建
Hwang
MMA-Self-defining function
NR LDPC 打孔-punctured
6-3 batch sum (*)
[untitled]
6-6 batch sum (*)
[piecemeal knowledge] [network composition] the mobile phone can be connected to the campus network, but the computer can't