提交 24713294 编写于 作者: L luxin

add 20 exercises

上级 142d462a
#include <stdio.h>
int main()
{
printf("Hello, World!\n");
return 0;
}
{
"multiline": [
{
"printf(\"Hello, World! \n\");": "printf(\"Hello, World! \n\")",
"return 0;": "return 0"
},
{
"return 0;": "return;"
},
{
"int main()": "int main"
}
]
}
\ No newline at end of file
# Hello World
输出 "Hello, World!" 字符串,找出正确的选项。
{
"keywords": [
"C语言特点",
"C语言特征",
"特点",
"特征",
"C语言"
],
"children": [
{
"语言简洁,使用方便灵活": {
"keywords": [
"语言简洁",
"方便灵活"
],
"children": []
}
},
{
"可移植性好": {
"keywords": [
"可移植性好",
"移植性"
],
"children": []
}
},
{
"表达能力强": {
"keywords": [
"表达能力强",
"表达能力"
],
"children": []
}
},
{
"表达方式灵活": {
"keywords": [
"表达方式灵活",
"表达方式"
],
"children": []
}
},
{
"可进行结构化程序设计": {
"keywords": [
"结构化程序设计",
"结构化",
"程序设计"
],
"children": []
}
},
{
"可以直接操作计算机硬件": {
"keywords": [
"操作计算机硬件",
"计算机硬件"
],
"children": []
}
},
{
"生成的目标代码质量高": {
"keywords": [
"目标代码质量高",
"目标代码"
],
"children": []
}
}
],
"export": [
{
"file": "features.c",
"variants": "features.json",
"depends": []
}
]
}
\ No newline at end of file
#include <stdio.h>
int main()
{
const int row = 7;
const int col = 50;
char feature_1[row][col] = {
'1. 语言简洁,使用方便灵活',
'2. 可移植性好',
'3. 表达能力强',
'4. 表达方式灵活',
'5. 可进行结构化程序设计',
'6. 可以直接操作计算机硬件',
'7. 生成的目标代码质量高'};
printf('********** C语言特点 **********\n');
for (int i = 0; i < row; ++i)
printf('%s\n', feature_1[i]);
printf('*******************************\n');
return 0;
}
\ No newline at end of file
# 打印C语言的特点
使用字符数组在控制台打印C语言的常见特点。请选出正确答案。
## A
```
#include <stdio.h>
int main()
{
const int row = 7;
const int col = 50;
char feature_1[row][col] = {
"1. 语言简洁,使用方便灵活",
"2. 可移植性好",
"3. 表达能力强",
"4. 表达方式灵活",
"5. 可进行结构化程序设计",
"6. 可以直接操作计算机硬件",
"7. 生成的目标代码质量高"};
printf("********** C语言特点 **********\n");
for (int i = 0; i < row; ++i)
printf("%s\n", feature_1[i]);
printf("*******************************\n");
return 0;
}
```
## B
```
#include <stdio.h>
int main()
{
const int row = 7;
const int col = 50;
char feature_1[row][col] = {
"1. 语言简洁,使用方便灵活",
"2. 可移植性好",
"3. 表达能力强",
"4. 表达方式灵活",
"5. 可进行结构化程序设计",
"6. 可以直接操作计算机硬件",
"7. 生成的目标代码质量高"};
print("********** C语言特点 **********\n");
for (int i = 0; i < row; ++i)
print("%s\n", feature_1[i]);
print("*******************************\n");
return 0;
}
```
## C
```
#include <stdio.h>
int main()
{
const int row = 7;
const int col = 50;
char feature_1[row][col] = {
"1. 语言简洁,使用方便灵活",
"2. 可移植性好",
"3. 表达能力强",
"4. 表达方式灵活",
"5. 可进行结构化程序设计",
"6. 可以直接操作计算机硬件",
"7. 生成的目标代码质量高"};
printf("********** C语言特点 **********\n");
for (int i = 0; i < row; ++i)
printf("%c\n", feature_1[i]);
printf("*******************************\n");
return 0;
}
```
## D
```
#include <stdio.h>
int main()
{
const int row = 7;
const int col = 50;
char feature_1[row][col] = {
'1. 语言简洁,使用方便灵活',
'2. 可移植性好',
'3. 表达能力强',
'4. 表达方式灵活',
'5. 可进行结构化程序设计',
'6. 可以直接操作计算机硬件',
'7. 生成的目标代码质量高'};
printf('********** C语言特点 **********\n');
for (int i = 0; i < row; ++i)
printf('%s\n', feature_1[i]);
printf('*******************************\n');
return 0;
}
```
{
"keywords": [
"C语言标准",
"语言标准",
"C语言"
],
"children": [
{
"Traditional C": {
"keywords": [
"TraditionalC"
],
"children": []
}
},
{
"C89": {
"keywords": [
"C89"
],
"children": []
}
},
{
"C95": {
"keywords": [
"C95"
],
"children": []
}
},
{
"C99": {
"keywords": [
"C99"
],
"children": []
}
},
{
"C11": {
"keywords": [
"C11"
],
"children": []
}
},
{
"C17": {
"keywords": [
"C17"
],
"children": []
}
},
{
"C2x": {
"keywords": [
"C2x"
],
"children": []
}
}
],
"export": []
}
\ No newline at end of file
{
"keywords": [
"编程机制",
"C语言"
],
"children": [
{
"目标代码文件、可执行文件和库": {
"keywords": [
"目标代码文件",
"可执行文件",
"C语言库",
"C语言"
],
"children": []
}
},
{
"UNIX系统": {
"keywords": [
"UNIX系统",
"UNIX",
"C语言"
],
"children": []
}
},
{
"Linux": {
"keywords": [
"Linux",
"C语言"
],
"children": []
}
},
{
"Windows": {
"keywords": [
"Windows",
"Linux",
"C语言"
],
"children": []
}
},
{
"Macintosh": {
"keywords": [
"Macintosh",
"C语言"
],
"children": []
}
},
{
"GNU编译器集合和LLVM项目": {
"keywords": [
"GNU编译器",
"GNU",
"LLVM项目",
"LLVM",
"C语言"
],
"children": []
}
},
{
"命令行编译器": {
"keywords": [
"命令行编译器",
"命令行",
"C语言"
],
"children": []
}
},
{
"集成开发环境": {
"keywords": [
"集成开发环境",
"IDE",
"C语言"
],
"children": []
}
}
],
"export": []
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"数据类型",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
{
"keywords": [
"常量",
"C语言"
],
"children": [],
"export": [
{
"file": "constants.c",
"variants": "constants.json",
"depends": []
}
]
}
\ No newline at end of file
#include <stdio.h>
#define PI 3.14
int main()
{
float radius = 2.0;
float area = PI * radius * radius;
printf("半径为%.2f的圆,面积是%.2f", radius, area);
return 0;
}
\ No newline at end of file
{
"multiline": [
{
"#define PI 3.14": "#define 3.14 PI"
},
{
"#define PI 3.14": "#define PI 3.14;"
},
{
"printf(\"半径为%.2f的圆,面积是%.2f\", radius, area);": "printf(\"半径为%d的圆,面积是%d\", radius, area);"
}
]
}
\ No newline at end of file
# 常量:计算圆的面积
使用常量表示圆周率$\pi$,并计算半径为2的圆的面积。请从以下选项中找出正确答案。
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"数据类型",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
#include <stdbool.h>
#include <stdio.h>
int main()
{
int student_id = 1001;
char name[] = "张三";
char sex[] = "男";
int age = 18;
bool only_child = true;
float height = 170.50;
float weight = 55.25;
printf("学号:\t%d\n", student_id);
printf("姓名:\t%s\n", name);
printf("性别:\t%s\n", sex);
printf("年龄:\t%d\n", age);
printf("身高:\t%.2f\n", height);
printf("体重:\t%.2f\n", weight);
printf("是否独生子女:\t%s\n", only_child ? "是": "否");
return 0;
}
\ No newline at end of file
# 打印学生基本信息
用不同的基本数据类型保存一名学生的各项信息,并打印输出。请选出正确答案。
## A
```
#include <stdbool.h>
#include <stdio.h>
int main()
{
int student_id = 1001;
char name[] = "张三";
char sex[] = "男";
int age = 18;
bool only_child = true;
float height = 170.50;
float weight = 55.25;
printf("学号:\t%d\n", student_id);
printf("姓名:\t%s\n", name);
printf("性别:\t%s\n", sex);
printf("年龄:\t%d\n", age);
printf("身高:\t%.2f\n", height);
printf("体重:\t%.2f\n", weight);
printf("是否独生子女:\t%s\n", only_child ? "是": "否");
return 0;
}
```
## B
```
#include <stdbool.h>
#include <stdio.h>
int main()
{
int student_id = 1001;
char name[] = "张三";
char sex = '男';
int age = 18;
bool only_child = true;
float height = 170.50;
float weight = 55.25;
printf("学号:\t%d\n", student_id);
printf("姓名:\t%s\n", name);
printf("性别:\t%c\n", sex);
printf("年龄:\t%d\n", age);
printf("身高:\t%.2f\n", height);
printf("体重:\t%.2f\n", weight);
printf("是否独生子女:\t%c\n", only_child ? '是': '否');
return 0;
}
```
## C
```
#include <stdbool.h>
#include <stdio.h>
int main()
{
int student_id = 1001;
char name[] = "张三";
char sex[] = "男";
int age = 18;
bool only_child = true;
float height = 170.50;
float weight = 55.25;
printf("学号:\t%d\n", student_id);
printf("姓名:\t%s\n", name);
printf("性别:\t%s\n", sex);
printf("年龄:\t%d\n", age);
printf("身高:\t%d\n", height);
printf("体重:\t%d\n", weight);
printf("是否独生子女:\t%s\n", only_child ? "是": "否");
return 0;
}
```
## D
```
#include <stdbool.h>
#include <stdio.h>
int main()
{
int student_id = 1001;
char name[] = "张三";
char sex[] = "男";
int age = 18;
bool only_child = true;
int height = 170.50;
int weight = 55.25;
printf("学号:\t%d\n", student_id);
printf("姓名:\t%s\n", name);
printf("性别:\t%s\n", sex);
printf("年龄:\t%d\n", age);
printf("身高:\t%d\n", height);
printf("体重:\t%d\n", weight);
printf("是否独生子女:\t%s\n", only_child ? "是": "否");
return 0;
}
```
\ No newline at end of file
{
"keywords": [
"基本数据类型",
"数据类型"
],
"children": [
{
"整数类型": {
"keywords": [
"整数类型",
"int"
],
"children": []
}
},
{
"浮点类型": {
"keywords": [
"浮点类型",
"float",
"double"
],
"children": []
}
},
{
"字符类型": {
"keywords": [
"字符类型",
"char"
],
"children": []
}
},
{
"布尔类型": {
"keywords": [
"布尔类型",
"boll"
],
"children": []
}
}
],
"export": [
{
"file": "basic_data_types.c",
"variants": "basic_data_types.json",
"depends": []
}
]
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"数据类型",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"数据类型",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"数据类型",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"运算符",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"运算符",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"运算符",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"运算符",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"运算符",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"运算符",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"运算符",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"运算符",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"运算符",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"运算符",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
#include <stdio.h>
int main()
{
int a = b = c = 10;
printf("a = %d\n", a);
printf("b = %d\n", b);
printf("c = %d\n", c);
return 0;
}
\ No newline at end of file
# 赋值运算符
实现三个变量的赋值操作,并输出三个变量的值。请选出错误答案。
## A
```
#include <stdio.h>
int main()
{
int a = b = c = 10;
printf("a = %d\n", a);
printf("b = %d\n", b);
printf("c = %d\n", c);
return 0;
}
```
## B
```
#include <stdio.h>
int main()
{
int a = 10, b = 10, c = 10;
printf("a = %d\n", a);
printf("b = %d\n", b);
printf("c = %d\n", c);
return 0;
}
```
## C
```
#include <stdio.h>
int main()
{
int a, b, c;
a = 10;
b = 10;
c = 10;
printf("a = %d\n", a);
printf("b = %d\n", b);
printf("c = %d\n", c);
return 0;
}
```
## D
```
#include <stdio.h>
int main()
{
int a, b, c;
a = b = c = 10;
printf("a = %d\n", a);
printf("b = %d\n", b);
printf("c = %d\n", c);
return 0;
}
```
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"赋值",
"运算符",
"赋值运算符",
"C语言"
],
"children": [],
"export": [
{
"file": "assignment_op.c",
"variants": "assignment_op.json",
"depends": []
}
]
}
\ No newline at end of file
#include <stdio.h>
#define upper 100
int main()
{
int i = 1;
while (i < upper)
{
if (i % 10 == 0)
printf("%d\n", i);
i++;
}
return 0;
}
\ No newline at end of file
# 打印被9整除的数
打印100以内(包含100)能被10整除的正整数。请选出正确答案。
## A
```
#include <stdio.h>
#define upper 100
int main()
{
int i = 1;
while (i++ < upper)
if (i % 10 == 0)
printf("%d\n", i);
return 0;
}
```
## B
```
#include <stdio.h>
#define upper 100
int main()
{
int i = 1;
while (i++ < upper)
if (i / 10 == 0)
printf("%d\n", i);
return 0;
}
```
## C
```
#include <stdio.h>
#define upper 100
int main()
{
int i = 1;
while (++i < upper)
if (i % 10 == 0)
printf("%d\n", i);
return 0;
}
```
## D
```
#include <stdio.h>
#define upper 100
int main()
{
int i = 1;
while (i < upper)
{
if (i % 10 == 0)
printf("%d\n", i);
i++;
}
return 0;
}
```
{
"keywords": [
"算术",
"算术运算符",
"运算符",
"C语言"
],
"children": [
{
"加法运算符": {
"keywords": [
"加法运算符",
"加法"
],
"children": []
}
},
{
"减法运算符": {
"keywords": [
"减法运算符",
"减法"
],
"children": []
}
},
{
"乘法运算符": {
"keywords": [
"乘法运算符",
"乘法"
],
"children": []
}
},
{
"除法运算符": {
"keywords": [
"除法运算符",
"除法"
],
"children": []
}
},
{
"求模运算符": {
"keywords": [
"求模运算符",
"求模"
],
"children": []
}
},
{
"递增运算符": {
"keywords": [
"递增运算符",
"递增"
],
"children": []
}
},
{
"递减运算符": {
"keywords": [
"递减运算符",
"递减"
],
"children": []
}
}
],
"export": [
{
"file": "arithmetic_op.c",
"variants": "arithmetic_op.json",
"depends": []
}
]
}
\ No newline at end of file
{
"keywords": [
"关系",
"关系运算符",
"运算符",
"C语言"
],
"children": [
{
"大于运算符": {
"keywords": [
"大于",
"大于运算符"
],
"children": []
}
},
{
"小于运算符": {
"keywords": [
"小于",
"小于运算符"
],
"children": []
}
},
{
"等于运算符": {
"keywords": [
"等于",
"等于运算符"
],
"children": []
}
},
{
"大于等于运算符": {
"keywords": [
"大于等于",
"大于等于运算符"
],
"children": []
}
},
{
"小于等于运算符": {
"keywords": [
"小于等于",
"小于等于运算符"
],
"children": []
}
},
{
"不等于运算符": {
"keywords": [
"不等于",
"不等于运算符"
],
"children": []
}
}
],
"export": [
{
"file": "relational_op.c",
"variants": "relational_op.json",
"depends": []
}
]
}
\ No newline at end of file
#include <stdio.h>
#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))
int main()
{
int start_1, end_1;
int start_2, end_2;
printf("请输入第1个闭区间:");
scanf("%d,%d", &start_1, &end_1);
printf("请输入第2个闭区间:");
scanf("%d,%d", &start_2, &end_2);
if (min(end_1, end_2) < max(start_1, start_2))
printf("两个区间不重叠!");
else
printf("两个区间重叠!");
return 0;
}
\ No newline at end of file
# 区间是否重叠
输入两个闭区间,并判断两个区间是否重叠。请选出错误答案。
## A
```
#include <stdio.h>
int main()
{
int start_1, end_1;
int start_2, end_2;
printf("请输入第1个闭区间:");
scanf("%d,%d", &start_1, &end_1);
printf("请输入第2个闭区间:");
scanf("%d,%d", &start_2, &end_2);
if (end_1 > start_2 || start_1 < end_2)
printf("两个区间不重叠!");
else
printf("两个区间重叠!");
return 0;
}
```
## B
```
#include <stdio.h>
int main()
{
int start_1, end_1;
int start_2, end_2;
printf("请输入第1个闭区间:");
scanf("%d,%d", &start_1, &end_1);
printf("请输入第2个闭区间:");
scanf("%d,%d", &start_2, &end_2);
if (end_1 < start_2 || start_1 > end_2)
printf("两个区间不重叠!");
else
printf("两个区间重叠!");
return 0;
}
```
## C
```
#include <stdio.h>
#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))
int main()
{
int start_1, end_1;
int start_2, end_2;
printf("请输入第1个闭区间:");
scanf("%d,%d", &start_1, &end_1);
printf("请输入第2个闭区间:");
scanf("%d,%d", &start_2, &end_2);
if (max(start_1, start_2) > min(end_1, end_2))
printf("两个区间不重叠!");
else
printf("两个区间重叠!");
return 0;
}
```
## D
```
#include <stdio.h>
#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))
int main()
{
int start_1, end_1;
int start_2, end_2;
printf("请输入第1个闭区间:");
scanf("%d,%d", &start_1, &end_1);
printf("请输入第2个闭区间:");
scanf("%d,%d", &start_2, &end_2);
if (min(end_1, end_2) < max(start_1, start_2))
printf("两个区间不重叠!");
else
printf("两个区间重叠!");
return 0;
}
```
{
"keywords": [
"逻辑",
"逻辑运算符",
"运算符",
"C语言"
],
"children": [
{
"逻辑与运算符": {
"keywords": [
"逻辑与",
"逻辑与运算符",
"与运算符"
],
"children": []
}
},
{
"逻辑或运算符": {
"keywords": [
"逻辑或",
"逻辑或运算符",
"或运算符"
],
"children": []
}
},
{
"逻辑非运算符": {
"keywords": [
"逻辑非",
"逻辑非运算符",
"非运算符"
],
"children": []
}
}
],
"export": [
{
"file": "logical_op.c",
"variants": "logical_op.json",
"depends": []
}
]
}
\ No newline at end of file
#include <stdio.h>
int main()
{
int year;
printf("请输人年份:");
scanf("%d", &year);
if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
printf("%d 是闰年\n", year);
else
printf("%d 非闰年\n", year);
return 0;
}
\ No newline at end of file
# 判断闰年
输入任意年份的正整数n,通过程序运行判断该年份是否为闰年。请选出错误答案。
满足以下任意一个条件的年份为闰年:
* 该年份能被400整除。
* 该年份能被4整除同时不能被 100 整除。、
## A
```
#include <stdio.h>
int main()
{
int year;
printf("请输人年份:");
scanf("%d", &year);
if (year % 400 == 0)
printf("%d 此年是闰年\n", year);
else
{
if (year % 4 == 0 || year % 100 != 0)
printf("%d 是闰年\n", year);
else
printf("%d 非闰年\n", year);
}
return 0;
}
```
## B
```
#include <stdio.h>
int main()
{
int year;
printf("请输人年份:");
scanf("%d", &year);
if (year % 400 == 0)
printf("%d 此年是闰年\n", year);
else
{
if (year % 4 == 0 && year % 100 != 0)
printf("%d 是闰年\n", year);
else
printf("%d 非闰年\n", year);
}
return 0;
}
```
## C
```
#include <stdio.h>
int main()
{
int year;
printf("请输人年份:");
scanf("%d", &year);
if (year % 400 == 0)
printf("%d 此年是闰年\n", year);
else
{
if (!(year % 4 != 0) && !(year % 100 == 0))
printf("%d 是闰年\n", year);
else
printf("%d 非闰年\n", year);
}
return 0;
}
```
## D
```
#include <stdio.h>
int main()
{
int year;
printf("请输人年份:");
scanf("%d", &year);
if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
printf("%d 是闰年\n", year);
else
printf("%d 非闰年\n", year);
return 0;
}
```
{
"keywords": [
"条件",
"条件运算符",
"运算符",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
#include <stdio.h>
int main()
{
int x, y, z;
x = y = 1;
z = x++, ++y, y++;
printf("%d,%d,%d\n", x, y, z);
}
\ No newline at end of file
# 运算符优先级与求值顺序
逗号运算符与自增运算符组成的混合表达式,请选出输出结果为 <font color=red>**2,3,1**</font> 的选项。
## A
```
#include <stdio.h>
int main()
{
int x, y, z;
x = y = 1;
z = x++, ++y, y++;
printf("%d,%d,%d\n", x, y, z);
}
```
## B
```
#include <stdio.h>
int main()
{
int x, y, z;
x = y = 1;
z = (x++, ++y, y++);
printf("%d,%d,%d\n", x, y, z);
}
```
## C
```
#include <stdio.h>
int main()
{
int x, y, z;
x = y = 1;
z = (x++, ++y), y++;
printf("%d,%d,%d\n", x, y, z);
}
```
## D
```
#include <stdio.h>
int main()
{
int x, y, z;
x = y = 1;
(z = (x++, ++y)), y++;
printf("%d,%d,%d\n", x, y, z);
}
```
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"表达式",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"表达式",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"表达式",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"表达式",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"表达式",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"表达式",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"表达式",
"C语言"
]
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"语句",
"控制流",
"C语言"
],
"children": [
{
"if语句": {
"keywords": [
"if语句",
"if"
],
"children": []
}
},
{
"if-else语句": {
"keywords": [
"if-else语句",
"if",
"else",
"if-else",
"ifelse",
"if else"
],
"children": []
}
},
{
"else-if语句": {
"keywords": [
"else-if语句",
"if",
"else",
"else-if",
"else-if",
"else if"
],
"children": []
}
},
{
"switch语句": {
"keywords": [
"switch语句",
"switch"
],
"children": []
}
}
],
"export": [
{
"file": "if.c",
"variants": "if.json",
"depends": []
},
{
"file": "ifelse.c",
"variants": "ifelse.json",
"depends": []
},
{
"file": "elseif.c",
"variants": "elseif.json",
"depends": []
},
{
"file": "switch.c",
"variants": "switch.json",
"depends": []
}
]
}
\ No newline at end of file
#include <stdio.h>
#include <math.h>
int main()
{
float a, b, c;
printf("请输入三角形的三条边:");
scanf("%f,%f,%f", &a, &b, &c);
if (a + b > c && b + c > a && a + c > b)
{
if (a == b && a == c)
printf("三角形是等边三角形\n");
else if (a == b || a == c || b == c)
printf("三角形是等腰三角形\n");
else if ((a * a + b * b == c * c) ||
(a * a + c * c == b * b) ||
(b * b + c * c == a * a))
printf("三角形是直角三角形\n");
else
printf("三角形是普通三角形\n");
}
else
printf("不能构成三角形\n");
return 0;
}
\ No newline at end of file
# 判断三角形的类型
输入三角形各边的长度,并判断三角形的类型。请选出正确答案。
## A
```
#include <stdio.h>
#include <math.h>
int main()
{
float a, b, c;
printf("请输入三角形的三条边:");
scanf("%f,%f,%f", &a, &b, &c);
if (a + b > c && b + c > a && a + c > b)
{
if (a == b && a == c)
printf("三角形是等边三角形\n");
else if (a == b || a == c || b == c)
printf("三角形是等腰三角形\n");
else if ((a * a + b * b == c * c) ||
(a * a + c * c == b * b) ||
(b * b + c * c == a * a))
printf("三角形是直角三角形\n");
else
printf("三角形是普通三角形\n");
}
else
printf("不能构成三角形\n");
return 0;
}
```
## B
```
#include <stdio.h>
#include <math.h>
int main()
{
float a, b, c;
printf("请输入三角形的三条边:");
scanf("%f,%f,%f", &a, &b, &c);
if (a + b > c && b + c > a && a + c > b)
{
if (a == b && a == c)
printf("三角形是等边三角形\n");
elseif (a == b || a == c || b == c)
printf("三角形是等腰三角形\n");
elseif ((a * a + b * b == c * c) ||
(a * a + c * c == b * b) ||
(b * b + c * c == a * a))
printf("三角形是直角三角形\n");
else
printf("三角形是普通三角形\n");
}
else
printf("不能构成三角形\n");
return 0;
}
```
## C
```
#include <stdio.h>
#include <math.h>
int main()
{
float a, b, c;
printf("请输入三角形的三条边:");
scanf("%f,%f,%f", &a, &b, &c);
if (a + b > c && b + c > a && a + c > b)
{
if (a == b && a == c):
printf("三角形是等边三角形\n");
else if (a == b || a == c || b == c):
printf("三角形是等腰三角形\n");
else if ((a * a + b * b == c * c) ||
(a * a + c * c == b * b) ||
(b * b + c * c == a * a)):
printf("三角形是直角三角形\n");
else:
printf("三角形是普通三角形\n");
}
else
printf("不能构成三角形\n");
return 0;
}
```
## D
```
#include <stdio.h>
#include <math.h>
int main()
{
float a, b, c;
printf("请输入三角形的三条边:");
scanf("%f,%f,%f", &a, &b, &c);
if (a + b > c && b + c > a && a + c > b)
{
if a == b && a == c
printf("三角形是等边三角形\n");
else if a == b || a == c || b == c
printf("三角形是等腰三角形\n");
else if (a * a + b * b == c * c) ||
(a * a + c * c == b * b) ||
(b * b + c * c == a * a)
printf("三角形是直角三角形\n");
else
printf("三角形是普通三角形\n");
}
else
printf("不能构成三角形\n");
return 0;
}
```
#include <stdio.h>
/* 交换x和y */
void swap(int* x, int* y)
{
int temp = *x;
*x = *y;
*y = temp;
}
int main()
{
int a, b, c;
printf("请输入 a,b,c:\n");
scanf("%d,%d,%d", &a, &b, &c);
if (a > b)
swap(&a, &b);
if (a > c)
swap(&a, &c);
if (b > c)
swap(&b, &c);
printf("升序排序结果:\n");
printf("%d,%d,%d", a, b, c);
return 0;
}
\ No newline at end of file
{
"multiline": [
{
"if (a > b)": "if a > b",
"if (a > c)": "if a > c",
"if (b > c)": "if b > c"
},
{
"if (a > b)": "if (a < b)",
"if (a > c)": "if (a < c)",
"if (b > c)": "if (b < c)"
},
{
"if (a > b)": "if (a > b):",
"if (a > c)": "if (a > c):",
"if (b > c)": "if (b > c):"
}
]
}
\ No newline at end of file
# 三个数从小到大排序并输出
任意输入3个整数,对这3个整数由小到大进行升序排序。请从以下选项中找出正确答案。
\ No newline at end of file
#include <stdio.h>
int main()
{
int num_1 = 0;
int num_2 = 0;
int max_num = 0;
printf("请输入第1个整数:");
scanf("%d", &num_1);
printf("请输入第2个整数:");
scanf("%d", &num_2);
if (num_1 >= num_2)
max_num = num_1;
else
max_num = num_2;
printf("两数之间的较大值为:%d", max_num);
return 0;
}
\ No newline at end of file
{
"multiline": [
{
"if (num_1 >= num_2)": "if (num_1 < num_2)"
},
{
"if (num_1 >= num_2)": "if (num_1 >= num_2):",
"else": "else:"
},
{
"if (num_1 >= num_2)": "if num_1 >= num_2"
}
]
}
\ No newline at end of file
# 两数较大值
输入两个整数,求两个整数之间的较大值。找出正确的选项。
\ No newline at end of file
#include<stdio.h>
int main()
{
int score;
printf("请输入成绩:");
scanf("%d",&score);
if ((score > 100) || (score < 0))
{
printf("请输入百分制的成绩!");
return 0;
}
int quotient = score / 10;
switch(quotient) {
case 10:
case 9:
printf("A");
break;
case 8:
printf("B");
break;
case 7:
printf("C");
break;
case 6:
printf("D");
break;
default:
printf("E");
break;
}
return 0;
}
\ No newline at end of file
{
"multiline": [
{
"int quotient = score / 10;": "int quotient = score % 10;"
},
{
"break;": "continue;"
},
{
"": ""
}
]
}
# 成绩转换
输入成绩(百分制),将成绩转换为相应的等级,并输出。具体转换规则为:
* 大于等于90分为等级A;
* 小于90分且大于等于80分为等级B;
* 小于80分且大于等于70分为等级C;
* 小于70分且大于等于60分为等级D;
* 小于60分为等级E。
请从以下选项中找出正确答案。
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"语句",
"控制流",
"C语言"
],
"children": [
{
"for循环": {
"keywords": [
"for循环",
"循环",
"for"
],
"children": []
}
},
{
"while循环": {
"keywords": [
"while循环",
"循环",
"while"
],
"children": []
}
},
{
"do-while循环": {
"keywords": [
"do-while循环",
"do-while",
"while",
"dowhile",
"do while"
],
"children": []
}
},
{
"break语句": {
"keywords": [
"break语句",
"break"
],
"children": []
}
},
{
"continue语句": {
"keywords": [
"continue语句",
"continue"
],
"children": []
}
},
{
"goto语句": {
"keywords": [
"goto语句",
"goto"
],
"children": []
}
}
],
"export": [
{
"file": "for.c",
"variants": "for.json",
"depends": []
},
{
"file": "while.c",
"variants": "while.json",
"depends": []
},
{
"file": "goto.c",
"variants": "goto.json",
"depends": []
}
]
}
\ No newline at end of file
#include <stdio.h>
int main()
{
int i = 0;
int j = 0;
for(i = 1; i <= 9; i++) {
for(j = 1; j <= 9; j++)
printf("%d*%d=%2d\t", i, j, i * j);
printf("\n");
}
return 0;
}
\ No newline at end of file
{
"multiline": [
{
"printf(\"%d*%d=%2d\t\", i, j, i*j);": "printf(\"%d+%d=%2d\t\", i, j, i+j);"
},
{
"for(i = 1; i <= 9; i++)": "for(i = 9; i <= 1; i--)",
"for(j = 1; j <= 9; j++)": "for(j = 9; j <= 1; j--)"
},
{
"for(i = 1; i <= 9; i++)": "for(i = 1; i <= 9; i++, j++)",
"for(j = 1; j <= 9; j++)": "for(j = 1; j <= 9; i++, j++)"
}
]
}
\ No newline at end of file
# 九九乘法表
使用for循环,打印九九乘法表。找出正确的选项。
\ No newline at end of file
#include <stdio.h>
int main()
{
int sum = 0;
int i = 0;
LOOP: if (++i <= 10)
{
goto LOOP;
sum += i;
}
printf("10以内的正整数之和为:%d", sum);
return 0;
}
\ No newline at end of file
# 求10以内的数之和
使用goto语句求10以内的正整数之和。请选出错误答案。
## A
```
#include <stdio.h>
int main()
{
int sum = 0;
int i = 0;
LOOP: if (++i <= 10)
{
goto LOOP;
sum += i;
}
printf("10以内的正整数之和为:%d", sum);
return 0;
}
```
## B
```
#include <stdio.h>
int main()
{
int sum = 0;
int i = 0;
LOOP: if (++i <= 10)
{
sum += i;
goto LOOP;
}
printf("10以内的正整数之和为:%d", sum);
return 0;
}
```
## C
```
#include <stdio.h>
int main()
{
int sum = 0;
int i = 0;
MARK: if (++i <= 10)
{
sum += i;
goto MARK;
}
printf("10以内的正整数之和为:%d", sum);
return 0;
}
```
## D
```
#include <stdio.h>
int main()
{
int sum = 0;
int i = 0;
LOOP: while (++i <= 10)
{
sum += i;
goto LOOP;
}
printf("10以内的正整数之和为:%d", sum);
return 0;
}
```
#include <stdio.h>
int main()
{
int a, b, c, m, t;
printf("请输入两个数:");
scanf("%d,%d", &a, &b);
if (a < b)
{
t = a;
a = b;
b = t;
}
m = a * b;
c = a % b;
do {
if (c != 0)
continue;
a = b;
b = c;
c = a % b;
}
while (1);
printf("最大公约数是:%d\n", b);
printf("最小公倍数是:%d\n", m / b);
}
\ No newline at end of file
# 最大公约数和最小公倍数
求两个正整数的最大公约数和最小公倍数。请选出错误答案。
1. 利用辗转相除法求出最大公约数。
2. 进而求出最小公倍数。
## A
```
#include <stdio.h>
int main()
{
int a, b, c, m, t;
printf("请输入两个数:");
scanf("%d,%d", &a, &b);
if (a < b)
{
t = a;
a = b;
b = t;
}
m = a * b;
c = a % b;
do {
if (c != 0)
continue;
a = b;
b = c;
c = a % b;
}
while (1);
printf("最大公约数是:%d\n", b);
printf("最小公倍数是:%d\n", m / b);
}
```
## B
```
#include <stdio.h>
int main()
{
int a, b, c, m, t;
printf("请输入两个数:");
scanf("%d,%d", &a, &b);
if (a < b)
{
t = a;
a = b;
b = t;
}
m = a * b;
c = a % b;
while (c != 0)
{
a = b;
b = c;
c = a % b;
}
printf("最大公约数是:%d\n", b);
printf("最小公倍数是:%d\n", m / b);
}
```
## C
```
#include <stdio.h>
int main()
{
int a, b, c, m, t;
printf("请输入两个数:");
scanf("%d,%d", &a, &b);
if (a < b)
{
t = a;
a = b;
b = t;
}
m = a * b;
c = a % b;
do {
if (c == 0)
break;
a = b;
b = c;
c = a % b;
}
while (1);
printf("最大公约数是:%d\n", b);
printf("最小公倍数是:%d\n", m / b);
}
```
## D
```
#include <stdio.h>
int main()
{
int a, b, c, m, t;
printf("请输入两个数:");
scanf("%d,%d", &a, &b);
if (a < b)
{
t = a;
a = b;
b = t;
}
m = a * b;
c = a % b;
while (1)
{
if (c == 0)
break;
a = b;
b = c;
c = a % b;
}
printf("最大公约数是:%d\n", b);
printf("最小公倍数是:%d\n", m / b);
}
```
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"语句",
"控制流",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"语句",
"控制流",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"语句",
"控制流",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"语句",
"控制流",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"语句",
"控制流",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"语句",
"控制流",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"语句",
"控制流",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [
"语句",
"控制流",
"C语言"
],
"children": [],
"export": []
}
\ No newline at end of file
......@@ -6,5 +6,11 @@
"C语言"
],
"children": [],
"export": []
"export": [
{
"file": "recursion.c",
"variants": "recursion.json",
"depends": []
}
]
}
\ No newline at end of file
#include <stdio.h>
int fibonacci(int i)
{
if (i == 0)
return 0;
if (i == 1)
return 1;
return fibonacci(i - 1) + fibonacci(i - 2);
}
int main()
{
int i = 0;
int n = 0;
printf("请输入你要打印的长度:");
scanf("%d", &n);
for (i = 0; i < n; i++)
printf("%d ", fibonacci(i));
return 0;
}
\ No newline at end of file
{
"multiline": [
{
"return fibonacci(i - 1) + fibonacci(i - 2);": "return fibonacci(i - 1) + fibonacci(i + 1);"
},
{
"if (i == 0)": "if (i == -1)"
},
{
"if (i == 1)": "if (i == -1)",
"return 1;": "return -1;"
}
]
}
\ No newline at end of file
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册