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

边栏推荐
- Cryptology Summary
- [collect first and use it sooner or later] 100 Flink high-frequency interview questions series (I)
- Hello go (XIV). Go language common standard library IV
- Winter vacation daily question 2022 [week1 not finished]
- 关于keil中,while循环条件不成立却无法跳出的问题
- SISO Decoder for min-sum(补充章节2)
- LeetCode_前缀树_中等_208. 实现 Trie (前缀树)
- [collect first and use it sooner or later] 100 Flink high-frequency interview questions series (II)
- 【C】 ATOI function implementation +offsetof implementation + exchange binary odd and even digits
- [practical Script] obtain the line number of a file, and then delete the file content.
猜你喜欢

網絡安全威脅情報體系
![Spring 2021 daily question [week7 not finished]](/img/93/582608e18bf6d78c552fa9478cdd77.jpg)
Spring 2021 daily question [week7 not finished]

夜神安装apk,以及bp代理

Initial egg framework

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

ctfhub-sql布尔盲注

SISO Decoder for a General (n, N - 1) SPC Code (Supplementary section 3)
![Spring 2021 daily question [week5 not finished]](/img/bd/35a8e0ded3b1a0727415c4cd95e781.jpg)
Spring 2021 daily question [week5 not finished]

viso的常见操作

ACL 2022:评估单词多义性不再困扰?一种新的基准“DIBIMT”
随机推荐
Talking about telework | community essay solicitation
Tle6389-2g V50's unique pwm/pfm control scheme has a duty cycle of up to 100%, forming a very low differential pressure - keshijin mall
About element location and size
SQL error injection 1
SISO Decoder for min-sum(补充章节2)
Sa-Token 单点登录 SSO模式二 URL重定向传播会话示例
Jsfinder, wafw00f installation, nmap configuration (msvcr120.dll file is missing)
在同花顺上面开股票账户好不好,安不安全?
【先收藏,早晚用得到】49个Flink高频面试题系列(二)
ACL 2022: is it no longer difficult to evaluate word polysemy? A new benchmark "dibimt"
SQL报错注入1
Global and Chinese market of web content management software 2022-2028: Research Report on technology, participants, trends, market size and share
Hello go (XIV). Go language common standard library IV
Mysql8 installation, Navicat installation, sqli labs setup
zabbix怎样自定义mysql监控项并触发告警
There are three standards and three methods, i.e. fast growth and quick realization. How to choose the direction for making short videos of we media?
General terms in security field
Class question: how to ensure that line table storage can be inserted at any time?
LeetCode_ Prefix tree_ Medium_ 208. implement trie (prefix tree)
Hello go (XIII). Go language common standard library III