当前位置:网站首页>[C语言]用结构体把输入的指定分数范围内的学生输出
[C语言]用结构体把输入的指定分数范围内的学生输出
2022-06-11 17:59:00 【跳舞的皮埃尔】
1、题目
学生的记录由姓名和成绩组成且在主函数中通过结构体数组初始化,无需输入。请编写函数实现把输入的指定分数范围内的学生通过结构体指针保存数据并输出。
要求:
- 使用结构体:
typedef struct Student
{
char name[20];
int score;
}Stu;
- 给定原始12位学生数据:
{
"HC105",85},{
"HC103",76},{
"HC102",69},{
"HC104",85},
{
"HC101",96},{
"HC107",72},{
"HC108",64},{
"HC106",87},
{
"HC115",85},{
"HC113",94},{
"HC112",64},{
"HC114",91}
- 使用子函数:void StructSearch(Stu *a, Stu *b, int low, int high ,int n,int *m)
输入格式: 输入两个分数
输出格式: 把在分数范围的学生信息输出
样例:
输入:75,86
输出:
HC105,85
HC103,76
HC104,85
HC115,85
2、完整代码
#include <stdio.h>
#define N 12
typedef struct Student
{
char name[20];
int score;
}Stu;
int StructSearch(Stu* a, Stu* b, int low, int high, int n, int* m)
{
int i, j = 0;
for (i = 0; i < n; i++)
{
if (a[i].score >= low && a[i].score <= high)
{
b[j++] = a[i];
}
}
m = j;
}
int main()
{
struct Student s[N] = {
{
"HC105",85},{
"HC103",76},{
"HC102",69},{
"HC104",85},
{
"HC101",96},{
"HC107",72},{
"HC108",64},{
"HC106",87},
{
"HC115",85},{
"HC113",94},{
"HC112",64},{
"HC114",91} };
struct Student h[N];
int i, j, n, low, high, t;
scanf("%d,%d", &low, &high);
n = StructSearch(s, h, low, high, 12, &n);
for (i = 0; i < n; i++)
printf("%s,%d\n", h[i].name, h[i].score);
}
3、截图

边栏推荐
- 10 ways to reset any user password
- SISO Decoder for Repetition(补充章节4)
- Codeworks round 479 (Div. 3) [done]
- Initial experience of MariaDB spider sharding engine
- New work of "the father of LSTM": a new method towards self correcting neural network
- Mysql8 installation, Navicat installation, sqli labs setup
- RadioGroup动态添加RadioButton
- ctf入门
- Ffmpeg hard codec inter QSV
- ISCSI详解(四)——ISCSI服务端配置实战
猜你喜欢

Ffmpeg hardware codec NVIDIA GPU
![Winter vacation daily question (improvement group) [end of week 4]](/img/67/89b5164712d8c4eb319b9266dd4b91.jpg)
Winter vacation daily question (improvement group) [end of week 4]
![[collect first and use it sooner or later] 100 Flink high-frequency interview questions series (II)](/img/cf/44b3983dd5d5f7b92d90d918215908.png)
[collect first and use it sooner or later] 100 Flink high-frequency interview questions series (II)

Why is the UDP stream set to 1316 bytes

Online excel file parsing and conversion to JSON format

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

“LSTM之父”新作:一种新方法,迈向自我修正的神经网络
![[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

网络安全威胁情报体系

SISO decoder for a general (n, n-1) SPC code (supplementary Chapter 3)
随机推荐
【C】 ATOI function implementation +offsetof implementation + exchange binary odd and even digits
Ffmpeg parity field frame interlace progressive command and code processing
"College entrance examination" volume sent to the big model: 442 people put forward 204 tasks to the big model, led by Google
任意用户密码重置的10种方式
Using packstack to quickly install openstack
Hello go (XII). Go language common standard library II
Ffmpeg hardware codec NVIDIA GPU
[not forgetting the original intention and forging ahead] 2021 Zhongchuang Suanli new year conference and anniversary celebration
Seeing the sudden death of a 28 year old employee, I was silent
Tle6288r is a 6-channel (150 MOhm) intelligent multi-channel switch using intelligent power technology - keshijin mall
6-8 reading and writing of structured files 1
Explain AI accelerators in detail: GPU, DPU, IPU, TPU... There are infinite possibilities for AI acceleration schemes
NR LDPC 打孔-punctured
[collect first and use it sooner or later] 49 Flink high-frequency interview questions series (II)
mysql8安装,navicat安装,sqli-labs搭建
Codeworks round 481 (Div. 3) [done]
[untitled]
Hello go (XIII). Go language common standard library III
[collect first and use it sooner or later] 100 Flink high-frequency interview questions series (III)
【先收藏,早晚用得到】49个Flink高频面试题系列(一)