Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CSDN 技术社区
skill_tree_c
提交
34cde60f
S
skill_tree_c
项目概览
CSDN 技术社区
/
skill_tree_c
通知
24
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
skill_tree_c
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
34cde60f
编写于
10月 22, 2021
作者:
L
luxin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add 7 exercises
上级
2e6e4ce6
变更
30
隐藏空白更改
内联
并排
Showing
30 changed file
with
1573 addition
and
33 deletion
+1573
-33
data/3.C语言高阶/1.结构体/1.结构体简介/config.json
data/3.C语言高阶/1.结构体/1.结构体简介/config.json
+10
-7
data/3.C语言高阶/1.结构体/1.结构体简介/structures.c
data/3.C语言高阶/1.结构体/1.结构体简介/structures.c
+28
-0
data/3.C语言高阶/1.结构体/1.结构体简介/structures.json
data/3.C语言高阶/1.结构体/1.结构体简介/structures.json
+7
-0
data/3.C语言高阶/1.结构体/1.结构体简介/structures.md
data/3.C语言高阶/1.结构体/1.结构体简介/structures.md
+111
-0
data/3.C语言高阶/1.结构体/2.结构体数组/config.json
data/3.C语言高阶/1.结构体/2.结构体数组/config.json
+4
-1
data/3.C语言高阶/1.结构体/2.结构体数组/structures_array.c
data/3.C语言高阶/1.结构体/2.结构体数组/structures_array.c
+36
-0
data/3.C语言高阶/1.结构体/2.结构体数组/structures_array.json
data/3.C语言高阶/1.结构体/2.结构体数组/structures_array.json
+7
-0
data/3.C语言高阶/1.结构体/2.结构体数组/structures_array.md
data/3.C语言高阶/1.结构体/2.结构体数组/structures_array.md
+154
-0
data/3.C语言高阶/1.结构体/3.结构体指针/config.json
data/3.C语言高阶/1.结构体/3.结构体指针/config.json
+10
-7
data/3.C语言高阶/1.结构体/3.结构体指针/structures_pointers.c
data/3.C语言高阶/1.结构体/3.结构体指针/structures_pointers.c
+24
-0
data/3.C语言高阶/1.结构体/3.结构体指针/structures_pointers.json
data/3.C语言高阶/1.结构体/3.结构体指针/structures_pointers.json
+7
-0
data/3.C语言高阶/1.结构体/3.结构体指针/structures_pointers.md
data/3.C语言高阶/1.结构体/3.结构体指针/structures_pointers.md
+115
-0
data/3.C语言高阶/1.结构体/4.结构体与函数/config.json
data/3.C语言高阶/1.结构体/4.结构体与函数/config.json
+2
-1
data/3.C语言高阶/1.结构体/4.结构体与函数/structures_n_func.c
data/3.C语言高阶/1.结构体/4.结构体与函数/structures_n_func.c
+41
-0
data/3.C语言高阶/1.结构体/4.结构体与函数/structures_n_func.json
data/3.C语言高阶/1.结构体/4.结构体与函数/structures_n_func.json
+7
-0
data/3.C语言高阶/1.结构体/4.结构体与函数/structures_n_func.md
data/3.C语言高阶/1.结构体/4.结构体与函数/structures_n_func.md
+180
-0
data/3.C语言高阶/1.结构体/5.链式结构/config.json
data/3.C语言高阶/1.结构体/5.链式结构/config.json
+10
-7
data/3.C语言高阶/1.结构体/5.链式结构/linked_list.c
data/3.C语言高阶/1.结构体/5.链式结构/linked_list.c
+64
-0
data/3.C语言高阶/1.结构体/5.链式结构/linked_list.json
data/3.C语言高阶/1.结构体/5.链式结构/linked_list.json
+7
-0
data/3.C语言高阶/1.结构体/5.链式结构/linked_list.md
data/3.C语言高阶/1.结构体/5.链式结构/linked_list.md
+272
-0
data/3.C语言高阶/2.联合体/config.json
data/3.C语言高阶/2.联合体/config.json
+0
-10
data/3.C语言高阶/2.联合体与枚举类型/1.联合体/config.json
data/3.C语言高阶/2.联合体与枚举类型/1.联合体/config.json
+12
-0
data/3.C语言高阶/2.联合体与枚举类型/1.联合体/unions.c
data/3.C语言高阶/2.联合体与枚举类型/1.联合体/unions.c
+43
-0
data/3.C语言高阶/2.联合体与枚举类型/1.联合体/unions.json
data/3.C语言高阶/2.联合体与枚举类型/1.联合体/unions.json
+7
-0
data/3.C语言高阶/2.联合体与枚举类型/1.联合体/unions.md
data/3.C语言高阶/2.联合体与枚举类型/1.联合体/unions.md
+184
-0
data/3.C语言高阶/2.联合体与枚举类型/2.枚举类型/config.json
data/3.C语言高阶/2.联合体与枚举类型/2.枚举类型/config.json
+12
-0
data/3.C语言高阶/2.联合体与枚举类型/2.枚举类型/enum.c
data/3.C语言高阶/2.联合体与枚举类型/2.枚举类型/enum.c
+36
-0
data/3.C语言高阶/2.联合体与枚举类型/2.枚举类型/enum.json
data/3.C语言高阶/2.联合体与枚举类型/2.枚举类型/enum.json
+7
-0
data/3.C语言高阶/2.联合体与枚举类型/2.枚举类型/enum.md
data/3.C语言高阶/2.联合体与枚举类型/2.枚举类型/enum.md
+166
-0
data/3.C语言高阶/2.联合体与枚举类型/config.json
data/3.C语言高阶/2.联合体与枚举类型/config.json
+10
-0
未找到文件。
data/3.C语言高阶/1.结构体/1.结构体简介/config.json
浏览文件 @
34cde60f
{
"node_id"
:
"569d5e11c4fc5de7844053d9a733c5e8"
,
"keywords"
:
[
"结构体"
,
"C语言"
],
"children"
:
[],
"export"
:
[]
"node_id"
:
"569d5e11c4fc5de7844053d9a733c5e8"
,
"keywords"
:
[
"结构体"
,
"C语言"
],
"children"
:
[],
"export"
:
[
"structures.json"
]
}
\ No newline at end of file
data/3.C语言高阶/1.结构体/1.结构体简介/structures.c
0 → 100644
浏览文件 @
34cde60f
#include <stdio.h>
struct
Student
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
group
;
float
score
;
}
int
main
()
{
struct
Student
stu
;
stu
.
name
=
"张三"
;
stu
.
id
=
1001
;
stu
.
age
=
16
;
stu
.
group
=
'A'
;
stu
.
score
=
95
.
50
;
printf
(
"========== 学生基本信息 ==========
\n
"
);
printf
(
"姓名:%s
\n
学号:%d
\n
年龄:%d
\n
所在小组:%c
\n
成绩:%.2f
\n
"
,
stu
.
name
,
stu
.
id
,
stu
.
age
,
stu
.
group
,
stu
.
score
);
printf
(
"==================================
\n
"
);
return
0
;
}
\ No newline at end of file
data/3.C语言高阶/1.结构体/1.结构体简介/structures.json
0 → 100644
浏览文件 @
34cde60f
{
"type"
:
"code_options"
,
"author"
:
"卢昕"
,
"source"
:
"structures.md"
,
"exercise_id"
:
"51df13a16d96417bb5dbe6476c1ec05f"
}
\ No newline at end of file
data/3.C语言高阶/1.结构体/1.结构体简介/structures.md
0 → 100644
浏览文件 @
34cde60f
# 结构体的定义与使用
定义一个学生结构体,并实例化一个学生对象,保存一个学生的基本信息,最后输出该学生信息。请选出错误答案。
## 答案
```
c
#include <stdio.h>
struct
Student
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
group
;
float
score
;
}
int
main
()
{
struct
Student
stu
;
stu
.
name
=
"张三"
;
stu
.
id
=
1001
;
stu
.
age
=
16
;
stu
.
group
=
'A'
;
stu
.
score
=
95
.
50
;
printf
(
"========== 学生基本信息 ==========
\n
"
);
printf
(
"姓名:%s
\n
学号:%d
\n
年龄:%d
\n
所在小组:%c
\n
成绩:%.2f
\n
"
,
stu
.
name
,
stu
.
id
,
stu
.
age
,
stu
.
group
,
stu
.
score
);
printf
(
"==================================
\n
"
);
return
0
;
}
```
## 选项
### A
```
c
#include <stdio.h>
struct
Student
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
group
;
float
score
;
};
int
main
()
{
struct
Student
stu
=
{
"张三"
,
1001
,
16
,
'A'
,
95
.
50
};
printf
(
"========== 学生基本信息 ==========
\n
"
);
printf
(
"姓名:%s
\n
学号:%d
\n
年龄:%d
\n
所在小组:%c
\n
成绩:%.2f
\n
"
,
stu
.
name
,
stu
.
id
,
stu
.
age
,
stu
.
group
,
stu
.
score
);
printf
(
"==================================
\n
"
);
return
0
;
}
```
### B
```
c
#include <stdio.h>
struct
Student
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
group
;
float
score
;
}
stu
=
{
"张三"
,
1001
,
16
,
'A'
,
95
.
50
};
int
main
()
{
printf
(
"========== 学生基本信息 ==========
\n
"
);
printf
(
"姓名:%s
\n
学号:%d
\n
年龄:%d
\n
所在小组:%c
\n
成绩:%.2f
\n
"
,
stu
.
name
,
stu
.
id
,
stu
.
age
,
stu
.
group
,
stu
.
score
);
printf
(
"==================================
\n
"
);
return
0
;
}
```
### C
```
c
#include <stdio.h>
typedef
struct
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
group
;
float
score
;
}
Student
;
int
main
()
{
Student
stu
=
{
"张三"
,
1001
,
16
,
'A'
,
95
.
50
};
printf
(
"========== 学生基本信息 ==========
\n
"
);
printf
(
"姓名:%s
\n
学号:%d
\n
年龄:%d
\n
所在小组:%c
\n
成绩:%.2f
\n
"
,
stu
.
name
,
stu
.
id
,
stu
.
age
,
stu
.
group
,
stu
.
score
);
printf
(
"==================================
\n
"
);
return
0
;
}
```
data/3.C语言高阶/1.结构体/2.结构体数组/config.json
浏览文件 @
34cde60f
...
...
@@ -5,5 +5,7 @@
"C语言"
],
"children"
:
[],
"export"
:
[]
"export"
:
[
"structures_array.json"
]
}
\ No newline at end of file
data/3.C语言高阶/1.结构体/2.结构体数组/structures_array.c
0 → 100644
浏览文件 @
34cde60f
#include <stdio.h>
#define NUM_STR 3
struct
Student
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
group
;
float
score
;
}
cls
[
NUM_STR
];
int
main
()
{
cls
=
{
{
"张三"
,
1001
,
16
,
'A'
,
95
.
50
},
{
"李四"
,
1002
,
15
,
'A'
,
90
.
00
},
{
"王五"
,
1003
,
16
,
'B'
,
80
.
50
}
};
float
total
=
0
,
average
=
0
;
printf
(
"=============== 学生基本信息 ===============
\n
"
);
printf
(
"姓名
\t
学号
\t
年龄
\t
小组
\t
成绩
\n
"
);
printf
(
"--------------------------------------------
\n
"
);
for
(
int
i
=
0
;
i
<
NUM_STR
;
++
i
)
{
printf
(
"%s
\t
%d
\t
%d
\t
%c
\t
%.2f
\n
"
,
cls
[
i
].
name
,
cls
[
i
].
id
,
cls
[
i
].
age
,
cls
[
i
].
group
,
cls
[
i
].
score
);
total
+=
cls
[
i
].
score
;
}
printf
(
"============================================
\n
"
);
average
=
total
/
NUM_STR
;
printf
(
"班级平均成绩:%.2f"
,
average
);
return
0
;
}
\ No newline at end of file
data/3.C语言高阶/1.结构体/2.结构体数组/structures_array.json
0 → 100644
浏览文件 @
34cde60f
{
"type"
:
"code_options"
,
"author"
:
"卢昕"
,
"source"
:
"structures_array.md"
,
"exercise_id"
:
"ce458884b396456d8b9993004272720e"
}
\ No newline at end of file
data/3.C语言高阶/1.结构体/2.结构体数组/structures_array.md
0 → 100644
浏览文件 @
34cde60f
# 结构体数组
定义一个学生结构体,并实例化一个结构体数组,用于保存一个班级所有学生的基本信息,最后输出所有学生基本信息,以及班级的学生平均成绩。请选出错误答案。
## 答案
```
c
#include <stdio.h>
#define NUM_STR 3
struct
Student
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
group
;
float
score
;
}
cls
[
NUM_STR
];
int
main
()
{
cls
=
{
{
"张三"
,
1001
,
16
,
'A'
,
95
.
50
},
{
"李四"
,
1002
,
15
,
'A'
,
90
.
00
},
{
"王五"
,
1003
,
16
,
'B'
,
80
.
50
}
};
float
total
=
0
,
average
=
0
;
printf
(
"=============== 学生基本信息 ===============
\n
"
);
printf
(
"姓名
\t
学号
\t
年龄
\t
小组
\t
成绩
\n
"
);
printf
(
"--------------------------------------------
\n
"
);
for
(
int
i
=
0
;
i
<
NUM_STR
;
++
i
)
{
printf
(
"%s
\t
%d
\t
%d
\t
%c
\t
%.2f
\n
"
,
cls
[
i
].
name
,
cls
[
i
].
id
,
cls
[
i
].
age
,
cls
[
i
].
group
,
cls
[
i
].
score
);
total
+=
cls
[
i
].
score
;
}
printf
(
"============================================
\n
"
);
average
=
total
/
NUM_STR
;
printf
(
"班级平均成绩:%.2f"
,
average
);
return
0
;
}
```
## 选项
### A
```
c
#include <stdio.h>
struct
Student
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
group
;
float
score
;
}
cls
[]
=
{
{
"张三"
,
1001
,
16
,
'A'
,
95
.
50
},
{
"李四"
,
1002
,
15
,
'A'
,
90
.
00
},
{
"王五"
,
1003
,
16
,
'B'
,
80
.
50
}
};
int
main
()
{
size_t
i
,
num_stu
=
sizeof
(
cls
)
/
sizeof
(
struct
Student
);
float
total
=
0
,
average
=
0
;
printf
(
"=============== 学生基本信息 ===============
\n
"
);
printf
(
"姓名
\t
学号
\t
年龄
\t
小组
\t
成绩
\n
"
);
printf
(
"--------------------------------------------
\n
"
);
for
(
i
=
0
;
i
<
num_stu
;
++
i
)
{
printf
(
"%s
\t
%d
\t
%d
\t
%c
\t
%.2f
\n
"
,
cls
[
i
].
name
,
cls
[
i
].
id
,
cls
[
i
].
age
,
cls
[
i
].
group
,
cls
[
i
].
score
);
total
+=
cls
[
i
].
score
;
}
printf
(
"============================================
\n
"
);
average
=
total
/
num_stu
;
printf
(
"班级平均成绩:%.2f"
,
average
);
return
0
;
}
```
### B
```
c
#include <stdio.h>
struct
Student
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
group
;
float
score
;
}
cls
[]
=
{
"张三"
,
1001
,
16
,
'A'
,
95
.
50
,
"李四"
,
1002
,
15
,
'A'
,
90
.
00
,
"王五"
,
1003
,
16
,
'B'
,
80
.
50
};
int
main
()
{
size_t
i
,
num_stu
=
sizeof
(
cls
)
/
sizeof
(
struct
Student
);
float
total
=
0
,
average
=
0
;
printf
(
"=============== 学生基本信息 ===============
\n
"
);
printf
(
"姓名
\t
学号
\t
年龄
\t
小组
\t
成绩
\n
"
);
printf
(
"--------------------------------------------
\n
"
);
for
(
i
=
0
;
i
<
num_stu
;
++
i
)
{
printf
(
"%s
\t
%d
\t
%d
\t
%c
\t
%.2f
\n
"
,
cls
[
i
].
name
,
cls
[
i
].
id
,
cls
[
i
].
age
,
cls
[
i
].
group
,
cls
[
i
].
score
);
total
+=
cls
[
i
].
score
;
}
printf
(
"============================================
\n
"
);
average
=
total
/
num_stu
;
printf
(
"班级平均成绩:%.2f"
,
average
);
return
0
;
}
```
### C
```
c
#include <stdio.h>
struct
Student
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
group
;
float
score
;
}
cls
[]
=
{
{.
name
=
"张三"
,
.
group
=
'A'
,
.
age
=
16
,
.
score
=
95
.
50
,
.
id
=
1001
},
{.
age
=
15
,
.
score
=
90
.
00
,
.
group
=
'A'
,
.
id
=
1002
,
.
name
=
"李四"
},
{.
group
=
'B'
,
.
age
=
16
,
.
name
=
"王五"
,
.
score
=
80
.
50
,
.
id
=
1003
}
};
int
main
()
{
size_t
i
,
num_stu
=
sizeof
(
cls
)
/
sizeof
(
struct
Student
);
float
total
=
0
,
average
=
0
;
printf
(
"=============== 学生基本信息 ===============
\n
"
);
printf
(
"姓名
\t
学号
\t
年龄
\t
小组
\t
成绩
\n
"
);
printf
(
"--------------------------------------------
\n
"
);
for
(
i
=
0
;
i
<
num_stu
;
++
i
)
{
printf
(
"%s
\t
%d
\t
%d
\t
%c
\t
%.2f
\n
"
,
cls
[
i
].
name
,
cls
[
i
].
id
,
cls
[
i
].
age
,
cls
[
i
].
group
,
cls
[
i
].
score
);
total
+=
cls
[
i
].
score
;
}
printf
(
"============================================
\n
"
);
average
=
total
/
num_stu
;
printf
(
"班级平均成绩:%.2f"
,
average
);
return
0
;
}
```
data/3.C语言高阶/1.结构体/3.结构体指针/config.json
浏览文件 @
34cde60f
{
"node_id"
:
"569d5e11c4fc5de7844053d9a733c5e8"
,
"keywords"
:
[
"结构体"
,
"C语言"
],
"children"
:
[],
"export"
:
[]
"node_id"
:
"569d5e11c4fc5de7844053d9a733c5e8"
,
"keywords"
:
[
"结构体"
,
"C语言"
],
"children"
:
[],
"export"
:
[
"structures_pointers.json"
]
}
\ No newline at end of file
data/3.C语言高阶/1.结构体/3.结构体指针/structures_pointers.c
0 → 100644
浏览文件 @
34cde60f
#include <stdio.h>
typedef
struct
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
group
;
float
score
;
}
Student
;
int
main
()
{
Student
stu
=
{
"张三"
,
1001
,
16
,
'A'
,
95
.
50
};
Student
*
stu_prt
=
&
stu
;
printf
(
"========== 学生基本信息 ==========
\n
"
);
printf
(
"姓名:%s
\n
学号:%d
\n
年龄:%d
\n
所在小组:%c
\n
成绩:%.2f
\n
"
,
*
stu_prt
.
name
,
*
stu_prt
.
id
,
*
stu_prt
.
age
,
*
stu_prt
.
group
,
*
stu_prt
.
score
);
printf
(
"==================================
\n
"
);
return
0
;
}
\ No newline at end of file
data/3.C语言高阶/1.结构体/3.结构体指针/structures_pointers.json
0 → 100644
浏览文件 @
34cde60f
{
"type"
:
"code_options"
,
"author"
:
"卢昕"
,
"source"
:
"structures_pointers.md"
,
"exercise_id"
:
"5fe2bafbe9974e62bf3544e50aefa3cc"
}
\ No newline at end of file
data/3.C语言高阶/1.结构体/3.结构体指针/structures_pointers.md
0 → 100644
浏览文件 @
34cde60f
# 结构体指针
定义一个学生结构体,并实例化一个学生对象,保存一个学生的基本信息,最后使用结构体指针访问和输出该学生信息。请选出错误答案。
## 答案
```
c
#include <stdio.h>
typedef
struct
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
group
;
float
score
;
}
Student
;
int
main
()
{
Student
stu
=
{
"张三"
,
1001
,
16
,
'A'
,
95
.
50
};
Student
*
stu_prt
=
&
stu
;
printf
(
"========== 学生基本信息 ==========
\n
"
);
printf
(
"姓名:%s
\n
学号:%d
\n
年龄:%d
\n
所在小组:%c
\n
成绩:%.2f
\n
"
,
*
stu_prt
.
name
,
*
stu_prt
.
id
,
*
stu_prt
.
age
,
*
stu_prt
.
group
,
*
stu_prt
.
score
);
printf
(
"==================================
\n
"
);
return
0
;
}
```
## 选项
### A
```
c
#include <stdio.h>
typedef
struct
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
group
;
float
score
;
}
Student
;
int
main
()
{
Student
stu
=
{
"张三"
,
1001
,
16
,
'A'
,
95
.
50
};
Student
*
stu_prt
=
&
stu
;
printf
(
"========== 学生基本信息 ==========
\n
"
);
printf
(
"姓名:%s
\n
学号:%d
\n
年龄:%d
\n
所在小组:%c
\n
成绩:%.2f
\n
"
,
stu_prt
->
name
,
stu_prt
->
id
,
stu_prt
->
age
,
stu_prt
->
group
,
stu_prt
->
score
);
printf
(
"==================================
\n
"
);
return
0
;
}
```
### B
```
c
#include <stdio.h>
struct
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
group
;
float
score
;
}
stu
=
{
"张三"
,
1001
,
16
,
'A'
,
95
.
50
},
*
stu_prt
=
&
stu
;
int
main
()
{
printf
(
"========== 学生基本信息 ==========
\n
"
);
printf
(
"姓名:%s
\n
学号:%d
\n
年龄:%d
\n
所在小组:%c
\n
成绩:%.2f
\n
"
,
stu_prt
->
name
,
stu_prt
->
id
,
stu_prt
->
age
,
stu_prt
->
group
,
stu_prt
->
score
);
printf
(
"==================================
\n
"
);
return
0
;
}
```
### C
```
c
#include <stdio.h>
typedef
struct
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
group
;
float
score
;
}
Student
;
int
main
()
{
Student
stu
;
Student
*
stu_prt
=
&
stu
;
stu_prt
->
name
=
"张三"
;
stu_prt
->
id
=
1001
;
stu_prt
->
age
=
16
;
stu_prt
->
group
=
'A'
;
stu_prt
->
score
=
95
.
50
;
printf
(
"========== 学生基本信息 ==========
\n
"
);
printf
(
"姓名:%s
\n
学号:%d
\n
年龄:%d
\n
所在小组:%c
\n
成绩:%.2f
\n
"
,
stu_prt
->
name
,
stu_prt
->
id
,
stu_prt
->
age
,
stu_prt
->
group
,
stu_prt
->
score
);
printf
(
"==================================
\n
"
);
return
0
;
}
```
data/3.C语言高阶/1.结构体/4.结构体与函数/config.json
浏览文件 @
34cde60f
...
...
@@ -5,5 +5,5 @@
"C语言"
],
"children"
:
[],
"export"
:
[]
"export"
:
[
"structures_n_func.json"
]
}
\ No newline at end of file
data/3.C语言高阶/1.结构体/4.结构体与函数/structures_n_func.c
0 → 100644
浏览文件 @
34cde60f
#include <stdio.h>
typedef
struct
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
group
;
float
score
;
}
Student
;
void
print_students
(
Student
stu
)
{
printf
(
"%s
\t
%d
\t
%d
\t
%c
\t
%.2f
\n
"
,
stu
.
name
,
stu
.
id
,
stu
.
age
,
stu
.
group
,
stu
.
score
);
}
int
main
()
{
Student
cls
[]
=
{
{
"张三"
,
1001
,
16
,
'A'
,
95
.
50
},
{
"李四"
,
1002
,
15
,
'A'
,
90
.
00
},
{
"王五"
,
1003
,
16
,
'B'
,
80
.
50
}
};
size_t
i
,
num_stu
=
sizeof
(
cls
)
/
sizeof
(
Student
);
float
total
=
0
,
average
=
0
;
printf
(
"=============== 学生基本信息 ===============
\n
"
);
printf
(
"姓名
\t
学号
\t
年龄
\t
小组
\t
成绩
\n
"
);
printf
(
"--------------------------------------------
\n
"
);
for
(
i
=
0
;
i
<
num_stu
;
++
i
)
{
print_students
(
cls
[
i
]);
total
+=
cls
[
i
].
score
;
}
printf
(
"============================================
\n
"
);
average
=
total
/
num_stu
;
printf
(
"班级平均成绩:%.2f"
,
average
);
return
0
;
}
\ No newline at end of file
data/3.C语言高阶/1.结构体/4.结构体与函数/structures_n_func.json
0 → 100644
浏览文件 @
34cde60f
{
"type"
:
"code_options"
,
"author"
:
"卢昕"
,
"source"
:
"structures_n_func.md"
,
"exercise_id"
:
"d05a0cfc3bd6483b9de9d0c97cc0ace8"
}
\ No newline at end of file
data/3.C语言高阶/1.结构体/4.结构体与函数/structures_n_func.md
0 → 100644
浏览文件 @
34cde60f
# 结构体与函数
定义一个学生结构体,并实例化一个结构体数组,用于保存一个班级所有学生的基本信息,最后输出所有学生基本信息,以及班级的学生平均成绩。请选出正确答案。
## 答案
```
c
#include <stdio.h>
typedef
struct
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
group
;
float
score
;
}
Student
;
void
print_students
(
Student
stu
)
{
printf
(
"%s
\t
%d
\t
%d
\t
%c
\t
%.2f
\n
"
,
stu
.
name
,
stu
.
id
,
stu
.
age
,
stu
.
group
,
stu
.
score
);
}
int
main
()
{
Student
cls
[]
=
{
{
"张三"
,
1001
,
16
,
'A'
,
95
.
50
},
{
"李四"
,
1002
,
15
,
'A'
,
90
.
00
},
{
"王五"
,
1003
,
16
,
'B'
,
80
.
50
}
};
size_t
i
,
num_stu
=
sizeof
(
cls
)
/
sizeof
(
Student
);
float
total
=
0
,
average
=
0
;
printf
(
"=============== 学生基本信息 ===============
\n
"
);
printf
(
"姓名
\t
学号
\t
年龄
\t
小组
\t
成绩
\n
"
);
printf
(
"--------------------------------------------
\n
"
);
for
(
i
=
0
;
i
<
num_stu
;
++
i
)
{
print_students
(
cls
[
i
]);
total
+=
cls
[
i
].
score
;
}
printf
(
"============================================
\n
"
);
average
=
total
/
num_stu
;
printf
(
"班级平均成绩:%.2f"
,
average
);
return
0
;
}
```
## 选项
### A
```
c
#include <stdio.h>
typedef
struct
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
group
;
float
score
;
}
Student
;
void
print_students
(
Student
*
stu
)
{
printf
(
"%s
\t
%d
\t
%d
\t
%c
\t
%.2f
\n
"
,
stu
->
name
,
stu
->
id
,
stu
->
age
,
stu
->
group
,
stu
->
score
);
}
int
main
()
{
Student
cls
[]
=
{
{
"张三"
,
1001
,
16
,
'A'
,
95
.
50
},
{
"李四"
,
1002
,
15
,
'A'
,
90
.
00
},
{
"王五"
,
1003
,
16
,
'B'
,
80
.
50
}
};
size_t
i
,
num_stu
=
sizeof
(
cls
)
/
sizeof
(
Student
);
float
total
=
0
,
average
=
0
;
printf
(
"=============== 学生基本信息 ===============
\n
"
);
printf
(
"姓名
\t
学号
\t
年龄
\t
小组
\t
成绩
\n
"
);
printf
(
"--------------------------------------------
\n
"
);
for
(
i
=
0
;
i
<
num_stu
;
++
i
)
{
print_students
(
cls
[
i
]);
total
+=
cls
[
i
].
score
;
}
printf
(
"============================================
\n
"
);
average
=
total
/
num_stu
;
printf
(
"班级平均成绩:%.2f"
,
average
);
return
0
;
}
```
### B
```
c
#include <stdio.h>
typedef
struct
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
group
;
float
score
;
}
Student
;
void
print_students
(
Student
*
stu
)
{
printf
(
"%s
\t
%d
\t
%d
\t
%c
\t
%.2f
\n
"
,
*
stu
.
name
,
*
stu
.
id
,
*
stu
.
age
,
*
stu
.
group
,
*
stu
.
score
);
}
int
main
()
{
Student
cls
[]
=
{
{
"张三"
,
1001
,
16
,
'A'
,
95
.
50
},
{
"李四"
,
1002
,
15
,
'A'
,
90
.
00
},
{
"王五"
,
1003
,
16
,
'B'
,
80
.
50
}
};
size_t
i
,
num_stu
=
sizeof
(
cls
)
/
sizeof
(
Student
);
float
total
=
0
,
average
=
0
;
printf
(
"=============== 学生基本信息 ===============
\n
"
);
printf
(
"姓名
\t
学号
\t
年龄
\t
小组
\t
成绩
\n
"
);
printf
(
"--------------------------------------------
\n
"
);
for
(
i
=
0
;
i
<
num_stu
;
++
i
)
{
print_students
(
&
cls
[
i
]);
total
+=
cls
[
i
].
score
;
}
printf
(
"============================================
\n
"
);
average
=
total
/
num_stu
;
printf
(
"班级平均成绩:%.2f"
,
average
);
return
0
;
}
```
### C
```
c
#include <stdio.h>
typedef
struct
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
group
;
float
score
;
}
Student
;
void
print_students
(
Student
stu
)
{
printf
(
"%s
\t
%d
\t
%d
\t
%c
\t
%.2f
\n
"
,
stu
->
name
,
stu
->
id
,
stu
->
age
,
stu
->
group
,
stu
->
score
);
}
int
main
()
{
Student
cls
[]
=
{
{
"张三"
,
1001
,
16
,
'A'
,
95
.
50
},
{
"李四"
,
1002
,
15
,
'A'
,
90
.
00
},
{
"王五"
,
1003
,
16
,
'B'
,
80
.
50
}
};
size_t
i
,
num_stu
=
sizeof
(
cls
)
/
sizeof
(
Student
);
float
total
=
0
,
average
=
0
;
printf
(
"=============== 学生基本信息 ===============
\n
"
);
printf
(
"姓名
\t
学号
\t
年龄
\t
小组
\t
成绩
\n
"
);
printf
(
"--------------------------------------------
\n
"
);
for
(
i
=
0
;
i
<
num_stu
;
++
i
)
{
print_students
(
cls
[
i
]);
total
+=
cls
[
i
].
score
;
}
printf
(
"============================================
\n
"
);
average
=
total
/
num_stu
;
printf
(
"班级平均成绩:%.2f"
,
average
);
return
0
;
}
```
data/3.C语言高阶/1.结构体/5.链式结构/config.json
浏览文件 @
34cde60f
{
"node_id"
:
"569d5e11c4fc5de7844053d9a733c5e8"
,
"keywords"
:
[
"结构体"
,
"C语言"
],
"children"
:
[],
"export"
:
[]
"node_id"
:
"569d5e11c4fc5de7844053d9a733c5e8"
,
"keywords"
:
[
"结构体"
,
"C语言"
],
"children"
:
[],
"export"
:
[
"linked_list.json"
]
}
\ No newline at end of file
data/3.C语言高阶/1.结构体/5.链式结构/linked_list.c
0 → 100644
浏览文件 @
34cde60f
#include <stdio.h>
#include <stdlib.h>
typedef
struct
Student
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
group
;
float
score
;
struct
Student
*
next
;
}
Student
,
*
Class
;
Class
init_class
()
{
Class
head
;
head
=
(
Student
*
)
malloc
(
sizeof
(
Student
));
if
(
!
head
)
return
NULL
;
head
->
next
=
NULL
;
return
head
;
}
void
insert_student
(
Class
cls
,
char
*
name
,
int
id
,
unsigned
int
age
,
char
group
,
float
score
)
{
Class
p
;
p
=
(
Student
*
)
malloc
(
sizeof
(
Student
));
p
->
name
=
name
,
p
->
id
=
id
,
p
->
age
=
age
,
p
->
group
=
group
,
p
->
score
=
score
;
p
->
next
=
cls
->
next
;
cls
->
next
=
p
;
}
void
print_class
(
const
Class
cls
)
{
Class
prt
=
NULL
;
float
total
=
0
,
average
=
0
;
int
num_stu
=
0
;
printf
(
"=============== 学生基本信息 ===============
\n
"
);
printf
(
"姓名
\t
学号
\t
年龄
\t
小组
\t
成绩
\n
"
);
printf
(
"--------------------------------------------
\n
"
);
for
(
prt
=
cls
->
next
;
prt
;
prt
=
prt
->
next
)
{
printf
(
"%s
\t
%d
\t
%d
\t
%c
\t
%.2f
\n
"
,
prt
->
name
,
prt
->
id
,
prt
->
age
,
prt
->
group
,
prt
->
score
);
total
+=
prt
->
score
;
++
num_stu
;
}
printf
(
"============================================
\n
"
);
average
=
total
/
num_stu
;
printf
(
"班级平均成绩:%.2f"
,
average
);
}
int
main
()
{
Class
cls
=
init_class
();
insert_student
(
cls
,
"王五"
,
1003
,
16
,
'B'
,
80
.
50
);
insert_student
(
cls
,
"李四"
,
1002
,
15
,
'A'
,
90
.
00
);
insert_student
(
cls
,
"张三"
,
1001
,
16
,
'A'
,
95
.
50
);
print_class
(
cls
);
return
0
;
}
\ No newline at end of file
data/3.C语言高阶/1.结构体/5.链式结构/linked_list.json
0 → 100644
浏览文件 @
34cde60f
{
"type"
:
"code_options"
,
"author"
:
"卢昕"
,
"source"
:
"linked_list.md"
,
"exercise_id"
:
"af79a964ebfa4116a79cd623357bee1d"
}
\ No newline at end of file
data/3.C语言高阶/1.结构体/5.链式结构/linked_list.md
0 → 100644
浏览文件 @
34cde60f
# 链式结构
定义一个学生结构体,并创建一个链表用于保存一个班级所有学生的基本信息,最后输出所有学生基本信息,以及班级的学生平均成绩。请选出正确答案。
## 答案
```
c
#include <stdio.h>
#include <stdlib.h>
typedef
struct
Student
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
group
;
float
score
;
struct
Student
*
next
;
}
Student
,
*
Class
;
Class
init_class
()
{
Class
head
;
head
=
(
Student
*
)
malloc
(
sizeof
(
Student
));
if
(
!
head
)
return
NULL
;
head
->
next
=
NULL
;
return
head
;
}
void
insert_student
(
Class
cls
,
char
*
name
,
int
id
,
unsigned
int
age
,
char
group
,
float
score
)
{
Class
p
;
p
=
(
Student
*
)
malloc
(
sizeof
(
Student
));
p
->
name
=
name
,
p
->
id
=
id
,
p
->
age
=
age
,
p
->
group
=
group
,
p
->
score
=
score
;
p
->
next
=
cls
->
next
;
cls
->
next
=
p
;
}
void
print_class
(
const
Class
cls
)
{
Class
prt
=
NULL
;
float
total
=
0
,
average
=
0
;
int
num_stu
=
0
;
printf
(
"=============== 学生基本信息 ===============
\n
"
);
printf
(
"姓名
\t
学号
\t
年龄
\t
小组
\t
成绩
\n
"
);
printf
(
"--------------------------------------------
\n
"
);
for
(
prt
=
cls
->
next
;
prt
;
prt
=
prt
->
next
)
{
printf
(
"%s
\t
%d
\t
%d
\t
%c
\t
%.2f
\n
"
,
prt
->
name
,
prt
->
id
,
prt
->
age
,
prt
->
group
,
prt
->
score
);
total
+=
prt
->
score
;
++
num_stu
;
}
printf
(
"============================================
\n
"
);
average
=
total
/
num_stu
;
printf
(
"班级平均成绩:%.2f"
,
average
);
}
int
main
()
{
Class
cls
=
init_class
();
insert_student
(
cls
,
"王五"
,
1003
,
16
,
'B'
,
80
.
50
);
insert_student
(
cls
,
"李四"
,
1002
,
15
,
'A'
,
90
.
00
);
insert_student
(
cls
,
"张三"
,
1001
,
16
,
'A'
,
95
.
50
);
print_class
(
cls
);
return
0
;
}
```
## 选项
### A
```
c
#include <stdio.h>
#include <stdlib.h>
typedef
struct
Student
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
group
;
float
score
;
struct
Student
*
next
;
}
Student
,
*
Class
;
Class
init_class
()
{
Class
head
;
head
=
(
Student
*
)
malloc
(
sizeof
(
Student
));
if
(
!
head
)
return
NULL
;
head
->
next
=
NULL
;
return
head
;
}
void
insert_student
(
Class
cls
,
char
*
name
,
int
id
,
unsigned
int
age
,
char
group
,
float
score
)
{
Class
p
;
p
=
(
Student
*
)
malloc
(
sizeof
(
Student
));
p
->
name
=
name
,
p
->
id
=
id
,
p
->
age
=
age
,
p
->
group
=
group
,
p
->
score
=
score
;
p
->
next
=
cls
->
next
;
cls
->
next
=
p
;
}
void
print_class
(
const
Class
cls
)
{
Class
prt
=
NULL
;
float
total
=
0
,
average
=
0
;
int
num_stu
=
0
;
printf
(
"=============== 学生基本信息 ===============
\n
"
);
printf
(
"姓名
\t
学号
\t
年龄
\t
小组
\t
成绩
\n
"
);
printf
(
"--------------------------------------------
\n
"
);
for
(
prt
=
cls
;
prt
;
prt
=
prt
->
next
)
{
printf
(
"%s
\t
%d
\t
%d
\t
%c
\t
%.2f
\n
"
,
prt
->
name
,
prt
->
id
,
prt
->
age
,
prt
->
group
,
prt
->
score
);
total
+=
prt
->
score
;
++
num_stu
;
}
printf
(
"============================================
\n
"
);
average
=
total
/
num_stu
;
printf
(
"班级平均成绩:%.2f"
,
average
);
}
int
main
()
{
Class
cls
=
init_class
();
insert_student
(
cls
,
"王五"
,
1003
,
16
,
'B'
,
80
.
50
);
insert_student
(
cls
,
"李四"
,
1002
,
15
,
'A'
,
90
.
00
);
insert_student
(
cls
,
"张三"
,
1001
,
16
,
'A'
,
95
.
50
);
print_class
(
cls
);
return
0
;
}
```
### B
```
c
#include <stdio.h>
#include <stdlib.h>
typedef
struct
Student
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
group
;
float
score
;
struct
Student
*
next
;
}
Student
,
*
Class
;
Class
init_class
()
{
Class
head
;
head
=
(
Student
*
)
malloc
(
sizeof
(
Student
));
if
(
!
head
)
return
NULL
;
head
->
next
=
NULL
;
return
head
;
}
void
insert_student
(
Class
cls
,
char
*
name
,
int
id
,
unsigned
int
age
,
char
group
,
float
score
)
{
Class
p
,
q
;
p
=
(
Student
*
)
malloc
(
sizeof
(
Student
));
p
->
name
=
name
,
p
->
id
=
id
,
p
->
age
=
age
,
p
->
group
=
group
,
p
->
score
=
score
;
cls
->
next
=
p
;
p
->
next
=
cls
->
next
;
}
void
print_class
(
const
Class
cls
)
{
Class
prt
=
NULL
;
float
total
=
0
,
average
=
0
;
int
num_stu
=
0
;
printf
(
"=============== 学生基本信息 ===============
\n
"
);
printf
(
"姓名
\t
学号
\t
年龄
\t
小组
\t
成绩
\n
"
);
printf
(
"--------------------------------------------
\n
"
);
for
(
prt
=
cls
->
next
;
prt
;
prt
=
prt
->
next
)
{
printf
(
"%s
\t
%d
\t
%d
\t
%c
\t
%.2f
\n
"
,
prt
->
name
,
prt
->
id
,
prt
->
age
,
prt
->
group
,
prt
->
score
);
total
+=
prt
->
score
;
++
num_stu
;
}
printf
(
"============================================
\n
"
);
average
=
total
/
num_stu
;
printf
(
"班级平均成绩:%.2f"
,
average
);
}
int
main
()
{
Class
cls
=
init_class
();
insert_student
(
cls
,
"王五"
,
1003
,
16
,
'B'
,
80
.
50
);
insert_student
(
cls
,
"李四"
,
1002
,
15
,
'A'
,
90
.
00
);
insert_student
(
cls
,
"张三"
,
1001
,
16
,
'A'
,
95
.
50
);
print_class
(
cls
);
return
0
;
}
```
### C
```
c
#include <stdio.h>
#include <stdlib.h>
typedef
struct
Student
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
group
;
float
score
;
struct
Student
*
next
;
}
Student
,
*
Class
;
Class
init_class
()
{
Class
head
;
head
=
(
Student
*
)
malloc
(
sizeof
(
Student
));
if
(
!
head
)
return
NULL
;
head
->
next
=
NULL
;
return
head
;
}
void
insert_student
(
Class
cls
,
char
*
name
,
int
id
,
unsigned
int
age
,
char
group
,
float
score
)
{
Class
p
;
p
=
(
Student
*
)
malloc
(
sizeof
(
Student
));
p
->
name
=
name
,
p
->
id
=
id
,
p
->
age
=
age
,
p
->
group
=
group
,
p
->
score
=
score
;
p
->
next
=
cls
->
next
;
cls
->
next
=
p
;
}
void
print_class
(
const
Class
cls
)
{
Class
prt
=
NULL
;
float
total
=
0
,
average
=
0
;
int
num_stu
=
0
;
printf
(
"=============== 学生基本信息 ===============
\n
"
);
printf
(
"姓名
\t
学号
\t
年龄
\t
小组
\t
成绩
\n
"
);
printf
(
"--------------------------------------------
\n
"
);
for
(
prt
=
(
*
cls
).
next
;
prt
;
++
prt
)
{
printf
(
"%s
\t
%d
\t
%d
\t
%c
\t
%.2f
\n
"
,
prt
->
name
,
prt
->
id
,
prt
->
age
,
prt
->
group
,
prt
->
score
);
total
+=
prt
->
score
;
++
num_stu
;
}
printf
(
"============================================
\n
"
);
average
=
total
/
num_stu
;
printf
(
"班级平均成绩:%.2f"
,
average
);
}
int
main
()
{
Class
cls
=
init_class
();
insert_student
(
cls
,
"王五"
,
1003
,
16
,
'B'
,
80
.
50
);
insert_student
(
cls
,
"李四"
,
1002
,
15
,
'A'
,
90
.
00
);
insert_student
(
cls
,
"张三"
,
1001
,
16
,
'A'
,
95
.
50
);
print_class
(
cls
);
return
0
;
}
```
data/3.C语言高阶/2.联合体/config.json
已删除
100644 → 0
浏览文件 @
2e6e4ce6
{
"node_id"
:
"569d5e11c4fc5de7844053d9a733c5e8"
,
"keywords"
:
[
"结构体"
,
"C语言"
],
"children"
:
[],
"export"
:
[]
}
\ No newline at end of file
data/3.C语言高阶/2.联合体与枚举类型/1.联合体/config.json
0 → 100644
浏览文件 @
34cde60f
{
"node_id"
:
"569d5e11c4fc5de7844053d9a733c5e8"
,
"keywords"
:
[
"联合体"
,
"共用体"
],
"children"
:
[],
"export"
:
[
"unions.json"
]
}
\ No newline at end of file
data/3.C语言高阶/2.联合体与枚举类型/1.联合体/unions.c
0 → 100644
浏览文件 @
34cde60f
#include <stdio.h>
#include <string.h>
#define STR_LEN 20
typedef
struct
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
profession
[
STR_LEN
];
union
{
float
score
;
char
course
[
STR_LEN
];
}
un
;
}
Person
;
int
main
()
{
Person
persons
[]
=
{
{.
name
=
"张三"
,
.
id
=
1001
,
.
age
=
16
,
.
profession
=
"学生"
,
.
un
.
score
=
95
.
50
},
{.
name
=
"李四"
,
.
id
=
1002
,
.
age
=
15
,
.
profession
=
"学生"
,
.
un
.
score
=
90
.
00
},
{.
name
=
"王五"
,
.
id
=
2001
,
.
age
=
26
,
.
profession
=
"教师"
,
.
un
.
course
=
"语文"
}
};
size_t
i
,
num_per
=
sizeof
(
persons
)
/
sizeof
(
Person
);
printf
(
"=============== 学生基本信息 ===============
\n
"
);
printf
(
"姓名
\t
学号/工号
\t
年龄
\t
身份
\t
成绩/学科
\n
"
);
printf
(
"--------------------------------------------
\n
"
);
for
(
i
=
0
;
i
<
num_per
;
++
i
)
{
Person
per
=
persons
[
i
];
if
(
strcmp
(
per
.
profession
,
"学生"
)
==
0
)
printf
(
"%s
\t
%d
\t\t
%d
\t
%s
\t
%.2f
\n
"
,
per
.
name
,
per
.
id
,
per
.
age
,
per
.
profession
,
per
.
un
.
score
);
else
printf
(
"%s
\t
%d
\t\t
%d
\t
%s
\t
%s
\n
"
,
per
.
name
,
per
.
id
,
per
.
age
,
per
.
profession
,
per
.
un
.
course
);
}
printf
(
"============================================
\n
"
);
return
0
;
}
\ No newline at end of file
data/3.C语言高阶/2.联合体与枚举类型/1.联合体/unions.json
0 → 100644
浏览文件 @
34cde60f
{
"type"
:
"code_options"
,
"author"
:
"卢昕"
,
"source"
:
"unions.md"
,
"exercise_id"
:
"73886fb5ce5c4b1e9db67223b260ee72"
}
\ No newline at end of file
data/3.C语言高阶/2.联合体与枚举类型/1.联合体/unions.md
0 → 100644
浏览文件 @
34cde60f
# 联合体
定义一个师生信息结构体,并实例化一个结构体数组,用于保存师生的基本信息,其中
**un**
字段用于保存学生的成绩或者教师的教学科目,最后输出所有人员信息。请选出正确答案。
## 答案
```
c
#include <stdio.h>
#include <string.h>
#define STR_LEN 20
typedef
struct
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
profession
[
STR_LEN
];
union
{
float
score
;
char
course
[
STR_LEN
];
}
un
;
}
Person
;
int
main
()
{
Person
persons
[]
=
{
{.
name
=
"张三"
,
.
id
=
1001
,
.
age
=
16
,
.
profession
=
"学生"
,
.
un
.
score
=
95
.
50
},
{.
name
=
"李四"
,
.
id
=
1002
,
.
age
=
15
,
.
profession
=
"学生"
,
.
un
.
score
=
90
.
00
},
{.
name
=
"王五"
,
.
id
=
2001
,
.
age
=
26
,
.
profession
=
"教师"
,
.
un
.
course
=
"语文"
}
};
size_t
i
,
num_per
=
sizeof
(
persons
)
/
sizeof
(
Person
);
printf
(
"=============== 学生基本信息 ===============
\n
"
);
printf
(
"姓名
\t
学号/工号
\t
年龄
\t
身份
\t
成绩/学科
\n
"
);
printf
(
"--------------------------------------------
\n
"
);
for
(
i
=
0
;
i
<
num_per
;
++
i
)
{
Person
per
=
persons
[
i
];
if
(
strcmp
(
per
.
profession
,
"学生"
)
==
0
)
printf
(
"%s
\t
%d
\t\t
%d
\t
%s
\t
%.2f
\n
"
,
per
.
name
,
per
.
id
,
per
.
age
,
per
.
profession
,
per
.
un
.
score
);
else
printf
(
"%s
\t
%d
\t\t
%d
\t
%s
\t
%s
\n
"
,
per
.
name
,
per
.
id
,
per
.
age
,
per
.
profession
,
per
.
un
.
course
);
}
printf
(
"============================================
\n
"
);
return
0
;
}
```
## 选项
### A
```
c
#include <stdio.h>
#include <string.h>
#define STR_LEN 20
typedef
struct
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
profession
[
STR_LEN
];
union
{
float
score
;
char
course
[
STR_LEN
];
}
un
;
}
Person
;
int
main
()
{
Person
persons
[]
=
{
{.
name
=
"张三"
,
.
id
=
1001
,
.
age
=
16
,
.
profession
=
"学生"
,
.
un
.
score
=
95
.
50
},
{.
name
=
"李四"
,
.
id
=
1002
,
.
age
=
15
,
.
profession
=
"学生"
,
.
un
.
score
=
90
.
00
},
{.
name
=
"王五"
,
.
id
=
2001
,
.
age
=
26
,
.
profession
=
"教师"
,
.
un
.
course
=
"语文"
}
};
size_t
i
,
num_per
=
sizeof
(
persons
)
/
sizeof
(
Person
);
printf
(
"=============== 学生基本信息 ===============
\n
"
);
printf
(
"姓名
\t
学号/工号
\t
年龄
\t
身份
\t
成绩/学科
\n
"
);
printf
(
"--------------------------------------------
\n
"
);
for
(
i
=
0
;
i
<
num_per
;
++
i
)
{
Person
per
=
persons
[
i
];
printf
(
"%s
\t
%d
\t\t
%d
\t
%s
\t
%.2f
\n
"
,
per
.
name
,
per
.
id
,
per
.
age
,
per
.
profession
,
per
.
un
.
score
);
}
printf
(
"============================================
\n
"
);
return
0
;
}
```
### B
```
c
#include <stdio.h>
#include <string.h>
#define STR_LEN 20
typedef
struct
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
profession
[
STR_LEN
];
union
{
float
score
;
char
course
[
STR_LEN
];
}
un
;
}
Person
;
int
main
()
{
Person
persons
[]
=
{
{
"张三"
,
1001
,
16
,
"学生"
,
95
.
50
},
{
"李四"
,
1002
,
15
,
"学生"
,
90
.
00
},
{
"王五"
,
2001
,
26
,
"教师"
,
"语文"
}
};
size_t
i
,
num_per
=
sizeof
(
persons
)
/
sizeof
(
Person
);
printf
(
"=============== 学生基本信息 ===============
\n
"
);
printf
(
"姓名
\t
学号/工号
\t
年龄
\t
身份
\t
成绩/学科
\n
"
);
printf
(
"--------------------------------------------
\n
"
);
for
(
i
=
0
;
i
<
num_per
;
++
i
)
{
Person
per
=
persons
[
i
];
if
(
strcmp
(
per
.
profession
,
"学生"
)
==
0
)
printf
(
"%s
\t
%d
\t\t
%d
\t
%s
\t
%.2f
\n
"
,
per
.
name
,
per
.
id
,
per
.
age
,
per
.
profession
,
per
.
un
.
score
);
else
printf
(
"%s
\t
%d
\t\t
%d
\t
%s
\t
%s
\n
"
,
per
.
name
,
per
.
id
,
per
.
age
,
per
.
profession
,
per
.
un
.
course
);
}
printf
(
"============================================
\n
"
);
return
0
;
}
```
### C
```
c
#include <stdio.h>
#include <string.h>
#define STR_LEN 20
typedef
struct
{
char
*
name
;
int
id
;
unsigned
int
age
;
char
profession
[
STR_LEN
];
union
un
{
float
score
;
char
course
[
STR_LEN
];
};
}
Person
;
int
main
()
{
Person
persons
[]
=
{
{.
name
=
"张三"
,
.
id
=
1001
,
.
age
=
16
,
.
profession
=
"学生"
,
.
un
.
score
=
95
.
50
},
{.
name
=
"李四"
,
.
id
=
1002
,
.
age
=
15
,
.
profession
=
"学生"
,
.
un
.
score
=
90
.
00
},
{.
name
=
"王五"
,
.
id
=
2001
,
.
age
=
26
,
.
profession
=
"教师"
,
.
un
.
course
=
"语文"
}
};
size_t
i
,
num_per
=
sizeof
(
persons
)
/
sizeof
(
Person
);
printf
(
"=============== 学生基本信息 ===============
\n
"
);
printf
(
"姓名
\t
学号/工号
\t
年龄
\t
身份
\t
成绩/学科
\n
"
);
printf
(
"--------------------------------------------
\n
"
);
for
(
i
=
0
;
i
<
num_per
;
++
i
)
{
Person
per
=
persons
[
i
];
if
(
strcmp
(
per
.
profession
,
"学生"
)
==
0
)
printf
(
"%s
\t
%d
\t\t
%d
\t
%s
\t
%.2f
\n
"
,
per
.
name
,
per
.
id
,
per
.
age
,
per
.
profession
,
per
.
un
.
score
);
else
printf
(
"%s
\t
%d
\t\t
%d
\t
%s
\t
%s
\n
"
,
per
.
name
,
per
.
id
,
per
.
age
,
per
.
profession
,
per
.
un
.
course
);
}
printf
(
"============================================
\n
"
);
return
0
;
}
```
data/3.C语言高阶/2.联合体与枚举类型/2.枚举类型/config.json
0 → 100644
浏览文件 @
34cde60f
{
"node_id"
:
"569d5e11c4fc5de7844053d9a733c5e8"
,
"keywords"
:
[
"枚举"
,
"枚举类型"
],
"children"
:
[],
"export"
:
[
"enum.json"
]
}
\ No newline at end of file
data/3.C语言高阶/2.联合体与枚举类型/2.枚举类型/enum.c
0 → 100644
浏览文件 @
34cde60f
#include <stdio.h>
enum
week
{
Mon
,
Tues
,
Wed
,
Thurs
,
Fri
,
Sat
,
Sun
};
enum
week
dw
;
int
cal_day_of_week
(
int
y
,
int
m
,
int
d
)
{
int
dw
;
if
(
m
==
1
||
m
==
2
)
{
m
+=
12
;
y
--
;
}
dw
=
(
d
+
2
*
m
+
3
*
(
m
+
1
)
/
5
+
y
+
y
/
4
-
y
/
100
+
y
/
400
)
%
7
;
return
dw
;
}
int
main
()
{
int
year
,
month
,
day
;
printf
(
"请输入日期(年-月-日):
\n
"
);
scanf
(
"%d-%d-%d"
,
&
year
,
&
month
,
&
day
);
dw
=
cal_day_of_week
(
year
,
month
,
day
);
switch
(
dw
)
{
case
week
.
Mon
:
printf
(
"星期一
\n
"
);
break
;
case
week
.
Tues
:
printf
(
"星期二
\n
"
);
break
;
case
week
.
Wed
:
printf
(
"星期三
\n
"
);
break
;
case
week
.
Thurs
:
printf
(
"星期四
\n
"
);
break
;
case
week
.
Fri
:
printf
(
"星期五
\n
"
);
break
;
case
week
.
Sat
:
printf
(
"星期六
\n
"
);
break
;
case
week
.
Sun
:
printf
(
"星期日
\n
"
);
break
;
}
return
0
;
}
data/3.C语言高阶/2.联合体与枚举类型/2.枚举类型/enum.json
0 → 100644
浏览文件 @
34cde60f
{
"type"
:
"code_options"
,
"author"
:
"卢昕"
,
"source"
:
"enum.md"
,
"exercise_id"
:
"44888a39b3be432a854447cd603b348e"
}
\ No newline at end of file
data/3.C语言高阶/2.联合体与枚举类型/2.枚举类型/enum.md
0 → 100644
浏览文件 @
34cde60f
# 枚举类型
输入一个日期(年月日),输出该日期是星期几。请选出错误答案。
## 答案
```
c
#include <stdio.h>
enum
week
{
Mon
,
Tues
,
Wed
,
Thurs
,
Fri
,
Sat
,
Sun
};
enum
week
dw
;
int
cal_day_of_week
(
int
y
,
int
m
,
int
d
)
{
int
dw
;
if
(
m
==
1
||
m
==
2
)
{
m
+=
12
;
y
--
;
}
dw
=
(
d
+
2
*
m
+
3
*
(
m
+
1
)
/
5
+
y
+
y
/
4
-
y
/
100
+
y
/
400
)
%
7
;
return
dw
;
}
int
main
()
{
int
year
,
month
,
day
;
printf
(
"请输入日期(年-月-日):
\n
"
);
scanf
(
"%d-%d-%d"
,
&
year
,
&
month
,
&
day
);
dw
=
cal_day_of_week
(
year
,
month
,
day
);
switch
(
dw
)
{
case
week
.
Mon
:
printf
(
"星期一
\n
"
);
break
;
case
week
.
Tues
:
printf
(
"星期二
\n
"
);
break
;
case
week
.
Wed
:
printf
(
"星期三
\n
"
);
break
;
case
week
.
Thurs
:
printf
(
"星期四
\n
"
);
break
;
case
week
.
Fri
:
printf
(
"星期五
\n
"
);
break
;
case
week
.
Sat
:
printf
(
"星期六
\n
"
);
break
;
case
week
.
Sun
:
printf
(
"星期日
\n
"
);
break
;
}
return
0
;
}
```
## 选项
### A
```
c
#include <stdio.h>
enum
week
{
Mon
,
Tues
,
Wed
,
Thurs
,
Fri
,
Sat
,
Sun
};
enum
week
dw
;
int
cal_day_of_week
(
int
y
,
int
m
,
int
d
)
{
int
dw
;
if
(
m
==
1
||
m
==
2
)
{
m
+=
12
;
y
--
;
}
dw
=
(
d
+
2
*
m
+
3
*
(
m
+
1
)
/
5
+
y
+
y
/
4
-
y
/
100
+
y
/
400
)
%
7
;
return
dw
;
}
int
main
()
{
int
year
,
month
,
day
;
printf
(
"请输入日期(年-月-日):
\n
"
);
scanf
(
"%d-%d-%d"
,
&
year
,
&
month
,
&
day
);
dw
=
cal_day_of_week
(
year
,
month
,
day
);
switch
(
dw
)
{
case
Mon
:
printf
(
"星期一
\n
"
);
break
;
case
Tues
:
printf
(
"星期二
\n
"
);
break
;
case
Wed
:
printf
(
"星期三
\n
"
);
break
;
case
Thurs
:
printf
(
"星期四
\n
"
);
break
;
case
Fri
:
printf
(
"星期五
\n
"
);
break
;
case
Sat
:
printf
(
"星期六
\n
"
);
break
;
case
Sun
:
printf
(
"星期日
\n
"
);
break
;
}
return
0
;
}
```
### B
```
c
#include <stdio.h>
enum
week
{
Mon
=
0
,
Tues
=
1
,
Wed
=
2
,
Thurs
=
3
,
Fri
=
4
,
Sat
=
5
,
Sun
=
6
};
enum
week
dw
;
int
cal_day_of_week
(
int
y
,
int
m
,
int
d
)
{
int
dw
;
if
(
m
==
1
||
m
==
2
)
{
m
+=
12
;
y
--
;
}
dw
=
(
d
+
2
*
m
+
3
*
(
m
+
1
)
/
5
+
y
+
y
/
4
-
y
/
100
+
y
/
400
)
%
7
;
return
dw
;
}
int
main
()
{
int
year
,
month
,
day
;
printf
(
"请输入日期(年-月-日):
\n
"
);
scanf
(
"%d-%d-%d"
,
&
year
,
&
month
,
&
day
);
dw
=
cal_day_of_week
(
year
,
month
,
day
);
switch
(
dw
)
{
case
Mon
:
printf
(
"星期一
\n
"
);
break
;
case
Tues
:
printf
(
"星期二
\n
"
);
break
;
case
Wed
:
printf
(
"星期三
\n
"
);
break
;
case
Thurs
:
printf
(
"星期四
\n
"
);
break
;
case
Fri
:
printf
(
"星期五
\n
"
);
break
;
case
Sat
:
printf
(
"星期六
\n
"
);
break
;
case
Sun
:
printf
(
"星期日
\n
"
);
break
;
}
return
0
;
}
```
### C
```
c
#include <stdio.h>
enum
week
{
Mon
=
0
,
Tues
,
Wed
,
Thurs
,
Fri
,
Sat
,
Sun
};
enum
week
dw
;
int
cal_day_of_week
(
int
y
,
int
m
,
int
d
)
{
int
dw
;
if
(
m
==
1
||
m
==
2
)
{
m
+=
12
;
y
--
;
}
dw
=
(
d
+
2
*
m
+
3
*
(
m
+
1
)
/
5
+
y
+
y
/
4
-
y
/
100
+
y
/
400
)
%
7
;
return
dw
;
}
int
main
()
{
int
year
,
month
,
day
;
printf
(
"请输入日期(年-月-日):
\n
"
);
scanf
(
"%d-%d-%d"
,
&
year
,
&
month
,
&
day
);
dw
=
cal_day_of_week
(
year
,
month
,
day
);
switch
(
dw
)
{
case
Mon
:
printf
(
"星期一
\n
"
);
break
;
case
Tues
:
printf
(
"星期二
\n
"
);
break
;
case
Wed
:
printf
(
"星期三
\n
"
);
break
;
case
Thurs
:
printf
(
"星期四
\n
"
);
break
;
case
Fri
:
printf
(
"星期五
\n
"
);
break
;
case
Sat
:
printf
(
"星期六
\n
"
);
break
;
case
Sun
:
printf
(
"星期日
\n
"
);
break
;
}
return
0
;
}
```
data/3.C语言高阶/2.联合体与枚举类型/config.json
0 → 100644
浏览文件 @
34cde60f
{
"node_id"
:
"569d5e11c4fc5de7844053d9a733c5e8"
,
"keywords"
:
[
"联合体"
,
"共用体"
,
"枚举类型"
,
"枚举"
]
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录