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

边栏推荐
- [Golang]力扣Leetcode - 349. 两个数组的交集(哈希表)
- mysql8安装,navicat安装,sqli-labs搭建
- 安装mariadb 10.5.7(tar包安装)
- 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
- EditText 金额限制
- 【先收藏,早晚用得到】100个Flink高频面试题系列(二)
- “LSTM之父”新作:一种新方法,迈向自我修正的神经网络
- 安全领域常规术语
- Say no to credit card fraud! 100 lines of code to realize simplified real-time fraud detection
- Global and Chinese market of high frequency bipolar junction transistors 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

SISO Decoder for min-sum(补充章节2)

Expérience initiale du moteur de segmentation de l'araignée mariadb

Getting started with Wireshark
![[collect first and use it sooner or later] 100 Flink high-frequency interview questions series (III)](/img/cf/44b3983dd5d5f7b92d90d918215908.png)
[collect first and use it sooner or later] 100 Flink high-frequency interview questions series (III)

【C】 Compilation preprocessing and environment

async导致函数结果出乎意料,改变原来代码的意图;await is only valid in async functions and the top level bodies of modules

Database lock and transaction isolation level
![Codeworks round 479 (Div. 3) [done]](/img/a0/f3c6989d8f755c03076b237514ee64.jpg)
Codeworks round 479 (Div. 3) [done]

ctfhub-sql布尔盲注

SISO Decoder for SPC (补充章节1)
随机推荐
Initial egg framework
Spring 2021 daily question [end of week4]
SISO Decoder for Repetition(补充章节4)
SQL语句当查询条件为空时默认查询全部数据,不为空是则按照条件进行查询
MySQL/Redis 常见面试题汇总
【新手上路常见问答】关于项目管理
ctfhub-sql布尔盲注
Network Security Threat Intelligence System
Cryptology Summary
【C】 Compilation preprocessing and environment
ACL 2022: is it no longer difficult to evaluate word polysemy? A new benchmark "dibimt"
How to learn and self-study
6-5 count the number of words (file) (*)
【先收藏,早晚用得到】49个Flink高频面试题系列(一)
[collect first and use it sooner or later] 49 Flink high-frequency interview questions series (II)
[document operation] of ACM
Acwing game 40 [End]
Online excel file parsing and conversion to JSON format
RadioGroup动态添加RadioButton
HashSet集合存储学生对象并遍历