当前位置:网站首页>[c language] output the average score and the student data below or equal to the average score with the structure
[c language] output the average score and the student data below or equal to the average score with the structure
2022-06-11 18:18:00 【Dancing Pierre】
[C Language ] Use the structure to output the data of the average score and the students whose scores are lower than or equal to the average score
1、 subject
Student records consist of names and grades , Enter... In the main function 4 Data on students , Please write a function to calculate and return the average score output , And save and output the data of students whose scores are lower than or equal to the average through the structure pointer .
requirement :
- Use structure :
typedef struct Student
{
char name[20];
int score;
}Stu;
- Use sub functions :float StructAvg(Stu *a,Stu *b,int n,int *m)
- To output in the main function .
Input format : Input in sequence 4 Names and scores of students
Output format : Save and output the data of students whose scores are lower than or equal to the average
Examples :
Input :
KOBE 90
YAO 90
HC 80
JAMES 70
Output :
Avg=82.5
HC 80
JAMES 70
2、 Complete code
#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、 Screenshot

边栏推荐
- Global and Chinese markets of solid polymer aluminum capacitors 2022-2028: Research Report on technology, participants, trends, market size and share
- RadioGroup动态添加RadioButton
- [C语言]限制查找次数,输出次数内查找到的最大值
- ISCSI详解(四)——ISCSI服务端配置实战
- 互联网_业务分析概述
- “LSTM之父”新作:一种新方法,迈向自我修正的神经网络
- 系统的可扩展型
- Hwang
- [C语言]用结构体把平均分和低于等于平均分的学生数据输出
- Explain AI accelerators in detail: GPU, DPU, IPU, TPU... There are infinite possibilities for AI acceleration schemes
猜你喜欢

Jsfinder, wafw00f installation, nmap configuration (msvcr120.dll file is missing)

10 ways to reset any user password

任意用户密码重置的10种方式
![Codeworks round 479 (Div. 3) [done]](/img/a0/f3c6989d8f755c03076b237514ee64.jpg)
Codeworks round 479 (Div. 3) [done]

Hello go (XV). Go language common standard library V
![[c language] compress strings and add markup characters](/img/b7/f7918f3ee0c409faffc70addd5ee65.png)
[c language] compress strings and add markup characters
![[C语言]压缩字符串并添加标记字符](/img/b7/f7918f3ee0c409faffc70addd5ee65.png)
[C语言]压缩字符串并添加标记字符

Reading summary of nacos2.x source code

SISO decoder for min sum (supplementary Chapter 2)

ACL 2022:评估单词多义性不再困扰?一种新的基准“DIBIMT”
随机推荐
[collect first and use it sooner or later] 100 Flink high-frequency interview questions series (II)
Spring 2021 daily question [week3 not finished]
单选按钮 文字背景同时改变
Is it good or not to open a stock account on the flush? Is it safe?
Various poses for text modification using sed
ISCSI详解(四)——ISCSI服务端配置实战
[c language] output the students with the highest scores with a structure. There can be multiple highest scores
SISO Decoder for SPC (补充章节1)
Implementation of servlet file upload function (Commons fileUpload)
Codeworks round 481 (Div. 3) [done]
Say no to credit card fraud! 100 lines of code to realize simplified real-time fraud detection
Système d'information sur les menaces à la sécurité des réseaux
[C语言]用结构体把最高分的学生输出,可有多个最高分
软件需求工程复习
“LSTM之父”新作:一种新方法,迈向自我修正的神经网络
Can 400 fans earn 20W a month? How did you do it?
vulhub
[MapReduce] a complete Mr program case teaches you how to package and run with idea
Understanding of distributed transactions
Upload labs failed to pass the customs halfway and the middle road collapsed