diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/1.\345\207\275\346\225\260\347\232\204\345\243\260\346\230\216\344\270\216\345\256\232\344\271\211/config.json" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/1.\345\207\275\346\225\260\347\232\204\345\243\260\346\230\216\344\270\216\345\256\232\344\271\211/config.json" index c459827dec2e3db475d29a7e2dd1fb5569595777..adcd39860ab694ae921143cd66a19d5ebb659d5b 100644 --- "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/1.\345\207\275\346\225\260\347\232\204\345\243\260\346\230\216\344\270\216\345\256\232\344\271\211/config.json" +++ "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/1.\345\207\275\346\225\260\347\232\204\345\243\260\346\230\216\344\270\216\345\256\232\344\271\211/config.json" @@ -6,5 +6,5 @@ "C语言" ], "children": [], - "export": [] + "export": ["definition.json"] } \ No newline at end of file diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/1.\345\207\275\346\225\260\347\232\204\345\243\260\346\230\216\344\270\216\345\256\232\344\271\211/definition.c" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/1.\345\207\275\346\225\260\347\232\204\345\243\260\346\230\216\344\270\216\345\256\232\344\271\211/definition.c" new file mode 100644 index 0000000000000000000000000000000000000000..e70290fa3bba2339ad5958652259198997caa9dd --- /dev/null +++ "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/1.\345\207\275\346\225\260\347\232\204\345\243\260\346\230\216\344\270\216\345\256\232\344\271\211/definition.c" @@ -0,0 +1,21 @@ +#include + +void print_link(); +void print_skill_tree(); + +int main() +{ + print_skill_tree(); + return 0; +} + +void print_link() +{ + printf("https://bbs.csdn.net/skill/c"); +} + +void print_skill_tree() +{ + printf("欢迎访问\"C语言技能树\"网址:"); + print_link(); +} \ No newline at end of file diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/1.\345\207\275\346\225\260\347\232\204\345\243\260\346\230\216\344\270\216\345\256\232\344\271\211/definition.json" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/1.\345\207\275\346\225\260\347\232\204\345\243\260\346\230\216\344\270\216\345\256\232\344\271\211/definition.json" new file mode 100644 index 0000000000000000000000000000000000000000..dc3bebb4736e0a1f389deebf4b451f6ef5bc54ec --- /dev/null +++ "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/1.\345\207\275\346\225\260\347\232\204\345\243\260\346\230\216\344\270\216\345\256\232\344\271\211/definition.json" @@ -0,0 +1,6 @@ +{ + "type": "code_options", + "author": "卢昕", + "source": "definition.md", + "exercise_id":"7c71b281a3c5490e95f9ab3c99d110f0" +} \ No newline at end of file diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/1.\345\207\275\346\225\260\347\232\204\345\243\260\346\230\216\344\270\216\345\256\232\344\271\211/definition.md" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/1.\345\207\275\346\225\260\347\232\204\345\243\260\346\230\216\344\270\216\345\256\232\344\271\211/definition.md" new file mode 100644 index 0000000000000000000000000000000000000000..7596d9cebf922eb1e7298f0f3e4a4a761761ecf7 --- /dev/null +++ "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/1.\345\207\275\346\225\260\347\232\204\345\243\260\346\230\216\344\270\216\345\256\232\344\271\211/definition.md" @@ -0,0 +1,104 @@ +# 打印技能树名称和网址 + +定义两个函数,打印C语言技能树的名称和网址。请选出正确答案。 + +## 答案 +```c +#include + +void print_link(); +void print_skill_tree(); + +int main() +{ + print_skill_tree(); + return 0; +} + +void print_link() +{ + printf("https://bbs.csdn.net/skill/c"); +} + +void print_skill_tree() +{ + printf("欢迎访问\"C语言技能树\"网址:"); + print_link(); +} +``` + + +## 选项 +### A +```c +#include + +void print_skill_tree() +{ + printf("欢迎访问\"C语言技能树\"网址:"); + print_link(); +} + +void print_link() +{ + printf("https://bbs.csdn.net/skill/c"); +} + +int main() +{ + print_skill_tree(); + return 0; +} +``` + +### B +```c +#include + +void print_link(); +void print_skill_tree(); + +int main() +{ + print_skill_tree(); + return 0; +} + +void print_skill_tree() +{ + printf("欢迎访问\"C语言技能树\"网址:"); + + void print_link() + { + printf("https://bbs.csdn.net/skill/c"); + } + + print_link(); +} +``` + +### C +```c +#include + +void print_link(char); +void print_skill_tree(); + +int main() +{ + print_skill_tree(); + return 0; +} + +void print_link(char link[]) +{ + printf("%s", link); +} + +void print_skill_tree() +{ + printf("欢迎访问\"C语言技能树\"网址:"); + print_link("https://bbs.csdn.net/skill/c"); +} + +``` diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/3.\345\207\275\346\225\260\347\232\204\350\277\224\345\233\236/config.json" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/3.\345\207\275\346\225\260\347\232\204\350\277\224\345\233\236/config.json" index c459827dec2e3db475d29a7e2dd1fb5569595777..09c4d39fe5d16d7514e540e49a80fcfd6881c524 100644 --- "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/3.\345\207\275\346\225\260\347\232\204\350\277\224\345\233\236/config.json" +++ "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/3.\345\207\275\346\225\260\347\232\204\350\277\224\345\233\236/config.json" @@ -6,5 +6,5 @@ "C语言" ], "children": [], - "export": [] + "export": ["return.json"] } \ No newline at end of file diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/3.\345\207\275\346\225\260\347\232\204\350\277\224\345\233\236/return.json" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/3.\345\207\275\346\225\260\347\232\204\350\277\224\345\233\236/return.json" index 544b7b4ddde01a730b456b39d168580fbc83b99e..0d9c1819a04aa37dbdae3d41a65dee59e1444b96 100644 --- "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/3.\345\207\275\346\225\260\347\232\204\350\277\224\345\233\236/return.json" +++ "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/3.\345\207\275\346\225\260\347\232\204\350\277\224\345\233\236/return.json" @@ -1,3 +1,6 @@ { - + "type": "code_options", + "author": "卢昕", + "source": "return.md", + "exercise_id":"c08cb53f455d47fbbf244d2605f5ae6d" } \ No newline at end of file diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/3.\345\207\275\346\225\260\347\232\204\350\277\224\345\233\236/return.md" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/3.\345\207\275\346\225\260\347\232\204\350\277\224\345\233\236/return.md" index 02e00e7fd6959795ef4b85ba3f51f568a74fec88..591a8c77d5847dea3d160835b5e9e717a3f096cb 100644 --- "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/3.\345\207\275\346\225\260\347\232\204\350\277\224\345\233\236/return.md" +++ "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/3.\345\207\275\346\225\260\347\232\204\350\277\224\345\233\236/return.md" @@ -48,50 +48,8 @@ int main() ## 选项 -### A -```c -#include - -void prime(int n) -{ - int is_prime = 1, i; - if (n < 0) - { - printf("%d 是一个非法输入!\n", n); - return -1; - } - else if (n < 2) - { - printf("%d 不是一个素数!\n", n); - return 0; - } - - for (i = 2; i < n; i++) - if (n % i == 0) - { - is_prime = 0; - break; - } - - if(is_prime == 1) - printf("%d 是一个素数!\n", n); - else - printf("%d 不是一个素数!\n", n); -} - -int main() -{ - int num, is_prime; - printf("请输入一个整数:"); - scanf("%d", &num); - prime(num); - - return 0; -} -``` - -### B +### A ```c #include @@ -132,7 +90,7 @@ int main() } ``` -### C +### B ```c #include @@ -175,7 +133,7 @@ int main() } ``` -### D +### C ```c #include diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/4.\345\207\275\346\225\260\347\232\204\350\260\203\347\224\250/config.json" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/4.\345\207\275\346\225\260\347\232\204\350\260\203\347\224\250/config.json" index c459827dec2e3db475d29a7e2dd1fb5569595777..73a6d6e5226a44e45b708647e433e9a3ff43bf65 100644 --- "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/4.\345\207\275\346\225\260\347\232\204\350\260\203\347\224\250/config.json" +++ "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/4.\345\207\275\346\225\260\347\232\204\350\260\203\347\224\250/config.json" @@ -6,5 +6,5 @@ "C语言" ], "children": [], - "export": [] + "export": ["function_call.json"] } \ No newline at end of file diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/4.\345\207\275\346\225\260\347\232\204\350\260\203\347\224\250/function_call.c" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/4.\345\207\275\346\225\260\347\232\204\350\260\203\347\224\250/function_call.c" new file mode 100644 index 0000000000000000000000000000000000000000..eee609e98ee62474c8685282946aa279802dbfa0 --- /dev/null +++ "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/4.\345\207\275\346\225\260\347\232\204\350\260\203\347\224\250/function_call.c" @@ -0,0 +1,34 @@ +#include + +char* csdn() +{ + return "CSDN-->"; +} + +char* yueluqu() +{ + return "岳麓区-->"; +} + +char* changsha() +{ + return "长沙-->"; +} + +char* hunan() +{ + return "湖南-->"; +} + +char* china() +{ + return "中国-->"; +} + +int main() +{ + printf("%s%s%s%s%s", china(), hunan(), changsha(), yueluqu(), csdn()); + printf("https://www.csdn.net/"); + + return 0; +} \ No newline at end of file diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/4.\345\207\275\346\225\260\347\232\204\350\260\203\347\224\250/function_call.json" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/4.\345\207\275\346\225\260\347\232\204\350\260\203\347\224\250/function_call.json" new file mode 100644 index 0000000000000000000000000000000000000000..de836b8d47ff7972e6c818d7bb2a5afabbfdc1a1 --- /dev/null +++ "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/4.\345\207\275\346\225\260\347\232\204\350\260\203\347\224\250/function_call.json" @@ -0,0 +1,6 @@ +{ + "type": "code_options", + "author": "卢昕", + "source": "function_call.md", + "exercise_id":"41843efba027453c9f2eea82d794cdf6" +} \ No newline at end of file diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/4.\345\207\275\346\225\260\347\232\204\350\260\203\347\224\250/function_call.md" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/4.\345\207\275\346\225\260\347\232\204\350\260\203\347\224\250/function_call.md" new file mode 100644 index 0000000000000000000000000000000000000000..285f85c3ad8755b09a26298551817d1dd81a9f68 --- /dev/null +++ "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/4.\345\207\275\346\225\260\347\232\204\350\260\203\347\224\250/function_call.md" @@ -0,0 +1,167 @@ +# 打印函数调用顺序 + +基于函数调用的顺序,正确输出 **中国-->湖南-->长沙-->岳麓区-->CSDN-->https://www.csdn.net/** 。请选出错误答案。 + +## 答案 +```c +#include + +void csdn() +{ + printf("CSDN-->"); +} + +void yueluqu() +{ + printf("岳麓区-->"); + csdn(); +} + +void changsha() +{ + printf("长沙-->"); + yueluqu(); +} + +void hunan() +{ + printf("湖南-->"); + changsha(); +} + +void china() +{ + printf("中国-->"); + hunan(); +} + +china(); +printf("https://www.csdn.net/"); + +int main() +{ + return 0; +} +``` + +## 选项 +### A +```c +#include + +void csdn() +{ + printf("CSDN-->"); +} + +void yueluqu() +{ + printf("岳麓区-->"); +} + +void changsha() +{ + printf("长沙-->"); +} + +void hunan() +{ + printf("湖南-->"); +} + +void china() +{ + printf("中国-->"); +} + +int main() +{ + china(); + hunan(); + changsha(); + yueluqu(); + csdn(); + printf("https://www.csdn.net/"); + + return 0; +} +``` + +### B +```c +#include + +void csdn() +{ + printf("CSDN-->"); +} + +void yueluqu() +{ + printf("岳麓区-->"); + csdn(); +} + +void changsha() +{ + printf("长沙-->"); + yueluqu(); +} + +void hunan() +{ + printf("湖南-->"); + changsha(); +} + +void china() +{ + printf("中国-->"); +} + +int main() +{ + china(); + printf("https://www.csdn.net/"); + + return 0; +} +``` + +### C +```c +#include + +char* csdn() +{ + return "CSDN-->"; +} + +char* yueluqu() +{ + return "岳麓区-->"; +} + +char* changsha() +{ + return "长沙-->"; +} + +char* hunan() +{ + return "湖南-->"; +} + +char* china() +{ + return "中国-->"; +} + +int main() +{ + printf("%s%s%s%s%s", china(), hunan(), changsha(), yueluqu(), csdn()); + printf("https://www.csdn.net/"); + + return 0; +} +``` diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/6.\345\261\200\351\203\250\345\217\230\351\207\217\345\222\214\345\205\250\345\261\200\345\217\230\351\207\217/config.json" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/6.\345\261\200\351\203\250\345\217\230\351\207\217\345\222\214\345\205\250\345\261\200\345\217\230\351\207\217/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..212b0cb55650ae5dfc04a33ff029b9e8b697860a --- /dev/null +++ "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/6.\345\261\200\351\203\250\345\217\230\351\207\217\345\222\214\345\205\250\345\261\200\345\217\230\351\207\217/config.json" @@ -0,0 +1,10 @@ +{ + "node_id": "569d5e11c4fc5de7844053d9a733c5e8", + "keywords": [ + "C语言概述", + "概述", + "C语言" + ], + "children": [], + "export": ["global_n_local_var.json"] + } \ No newline at end of file diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/6.\345\261\200\351\203\250\345\217\230\351\207\217\345\222\214\345\205\250\345\261\200\345\217\230\351\207\217/global_n_local_var.c" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/6.\345\261\200\351\203\250\345\217\230\351\207\217\345\222\214\345\205\250\345\261\200\345\217\230\351\207\217/global_n_local_var.c" new file mode 100644 index 0000000000000000000000000000000000000000..e0c9724150263105c7a8669859cf29b55945fee5 --- /dev/null +++ "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/6.\345\261\200\351\203\250\345\217\230\351\207\217\345\222\214\345\205\250\345\261\200\345\217\230\351\207\217/global_n_local_var.c" @@ -0,0 +1,25 @@ +#include + +int s1, s2, s3; + +int vs(int a, int b, int c) +{ + int v; + v = a * b * c; + s1 = a * b; + s2 = b * c; + s3 = a * c; + return v; +} + +int main() +{ + int v, length, width, height; + printf("请分别输入长方体的长宽高:"); + scanf("%d,%d,%d", &length, &width, &height); + + v = vs(length, width, height); + printf("v=%d, s1=%d, s2=%d, s3=%d\n", v, s1, s2, s3); + + return 0; +} \ No newline at end of file diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/6.\345\261\200\351\203\250\345\217\230\351\207\217\345\222\214\345\205\250\345\261\200\345\217\230\351\207\217/global_n_local_var.json" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/6.\345\261\200\351\203\250\345\217\230\351\207\217\345\222\214\345\205\250\345\261\200\345\217\230\351\207\217/global_n_local_var.json" new file mode 100644 index 0000000000000000000000000000000000000000..314e87ae0eeff773459cdcbd7eb302edd2b19a77 --- /dev/null +++ "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/6.\345\261\200\351\203\250\345\217\230\351\207\217\345\222\214\345\205\250\345\261\200\345\217\230\351\207\217/global_n_local_var.json" @@ -0,0 +1,6 @@ +{ + "type": "code_options", + "author": "卢昕", + "source": "global_n_local_var.md", + "exercise_id":"8c862340818547858499a071f828bbba" +} \ No newline at end of file diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/6.\345\261\200\351\203\250\345\217\230\351\207\217\345\222\214\345\205\250\345\261\200\345\217\230\351\207\217/global_n_local_var.md" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/6.\345\261\200\351\203\250\345\217\230\351\207\217\345\222\214\345\205\250\345\261\200\345\217\230\351\207\217/global_n_local_var.md" new file mode 100644 index 0000000000000000000000000000000000000000..01b1bf0a1216e6e5e4541f83c312ed4048036d85 --- /dev/null +++ "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/6.\345\261\200\351\203\250\345\217\230\351\207\217\345\222\214\345\205\250\345\261\200\345\217\230\351\207\217/global_n_local_var.md" @@ -0,0 +1,118 @@ +# 长方体的体积和面积 + +根据长方体的长宽高求它的体积以及三个面的面积。找出正确的选项。 + +## 答案 +```c +#include + +int s1, s2, s3; + +int vs(int a, int b, int c) +{ + int v; + v = a * b * c; + s1 = a * b; + s2 = b * c; + s3 = a * c; + return v; +} + +int main() +{ + int v, length, width, height; + printf("请分别输入长方体的长宽高:"); + scanf("%d,%d,%d", &length, &width, &height); + + v = vs(length, width, height); + printf("v=%d, s1=%d, s2=%d, s3=%d\n", v, s1, s2, s3); + + return 0; +} +``` + +## 选项 +### A +```c +#include + +int vs(int a, int b, int c) +{ + int v; + v = a * b * c; + s1 = a * b; + s2 = b * c; + s3 = a * c; + return v; +} + +int s1, s2, s3; + +int main() +{ + int v, length, width, height; + printf("请分别输入长方体的长宽高:"); + scanf("%d,%d,%d", &length, &width, &height); + + v = vs(length, width, height); + printf("v=%d, s1=%d, s2=%d, s3=%d\n", v, s1, s2, s3); + + return 0; +} +``` + +### B +```c +#include + +int vs(int a, int b, int c) +{ + int v, s1, s2, s3; + v = a * b * c; + s1 = a * b; + s2 = b * c; + s3 = a * c; + return v; +} + +int main() +{ + int v, length, width, height; + printf("请分别输入长方体的长宽高:"); + scanf("%d,%d,%d", &length, &width, &height); + + v = vs(length, width, height); + printf("v=%d, s1=%d, s2=%d, s3=%d\n", v, s1, s2, s3); + + return 0; +} +``` + +### C +```c +#include + +int s1, s2, s3; + +int vs(int a, int b, int c) +{ + int v, s1, s2, s3; + v = a * b * c; + s1 = a * b; + s2 = b * c; + s3 = a * c; + return v; +} + +int main() +{ + int v, length, width, height; + printf("请分别输入长方体的长宽高:"); + scanf("%d,%d,%d", &length, &width, &height); + + v = vs(length, width, height); + printf("v=%d, s1=%d, s2=%d, s3=%d\n", v, s1, s2, s3); + + return 0; +} +``` diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/6.\345\206\205\351\203\250\345\207\275\346\225\260\345\222\214\345\244\226\351\203\250\345\207\275\346\225\260/config.json" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/7.\345\244\264\346\226\207\344\273\266/config.json" similarity index 100% rename from "data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/6.\345\206\205\351\203\250\345\207\275\346\225\260\345\222\214\345\244\226\351\203\250\345\207\275\346\225\260/config.json" rename to "data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/7.\345\244\264\346\226\207\344\273\266/config.json" diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/8.\345\244\264\346\226\207\344\273\266/config.json" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/8.\345\206\205\351\203\250\345\207\275\346\225\260\345\222\214\345\244\226\351\203\250\345\207\275\346\225\260/config.json" similarity index 100% rename from "data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/8.\345\244\264\346\226\207\344\273\266/config.json" rename to "data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/1.\345\207\275\346\225\260\344\270\216\347\250\213\345\272\217\347\273\223\346\236\204/8.\345\206\205\351\203\250\345\207\275\346\225\260\345\222\214\345\244\226\351\203\250\345\207\275\346\225\260/config.json" diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/5.\345\255\227\347\254\246\346\214\207\351\222\210\344\270\216\345\207\275\346\225\260/config.json" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/5.\346\214\207\351\222\210\346\225\260\347\273\204\344\273\245\345\217\212\346\214\207\345\220\221\346\214\207\351\222\210\347\232\204\346\214\207\351\222\210/config.json" similarity index 76% rename from "data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/5.\345\255\227\347\254\246\346\214\207\351\222\210\344\270\216\345\207\275\346\225\260/config.json" rename to "data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/5.\346\214\207\351\222\210\346\225\260\347\273\204\344\273\245\345\217\212\346\214\207\345\220\221\346\214\207\351\222\210\347\232\204\346\214\207\351\222\210/config.json" index 57fc5bddbc442b64a863db7aa0d19a90b6f40e97..587e428eed7d6528a67b4272bd8634eedee3ee07 100644 --- "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/5.\345\255\227\347\254\246\346\214\207\351\222\210\344\270\216\345\207\275\346\225\260/config.json" +++ "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/5.\346\214\207\351\222\210\346\225\260\347\273\204\344\273\245\345\217\212\346\214\207\345\220\221\346\214\207\351\222\210\347\232\204\346\214\207\351\222\210/config.json" @@ -5,5 +5,5 @@ "C语言" ], "children": [], - "export": [] + "export": ["pointers_array.json"] } \ No newline at end of file diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/5.\346\214\207\351\222\210\346\225\260\347\273\204\344\273\245\345\217\212\346\214\207\345\220\221\346\214\207\351\222\210\347\232\204\346\214\207\351\222\210/pointers_array.c" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/5.\346\214\207\351\222\210\346\225\260\347\273\204\344\273\245\345\217\212\346\214\207\345\220\221\346\214\207\351\222\210\347\232\204\346\214\207\351\222\210/pointers_array.c" new file mode 100644 index 0000000000000000000000000000000000000000..675e5fbc9084fd160d8dab78a57d89dde8ac79a5 --- /dev/null +++ "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/5.\346\214\207\351\222\210\346\225\260\347\273\204\344\273\245\345\217\212\346\214\207\345\220\221\346\214\207\351\222\210\347\232\204\346\214\207\351\222\210/pointers_array.c" @@ -0,0 +1,20 @@ +#include +#define LEN 5 + +int main() +{ + char *fruits[LEN] = { + "apple", + "cherry", + "grape", + "peach", + "watermelon" + }; + + for (int i = 0; i < LEN; ++fruits, ++i) + { + printf("%s\n", *fruits); + } + + return 0; +} \ No newline at end of file diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/5.\346\214\207\351\222\210\346\225\260\347\273\204\344\273\245\345\217\212\346\214\207\345\220\221\346\214\207\351\222\210\347\232\204\346\214\207\351\222\210/pointers_array.json" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/5.\346\214\207\351\222\210\346\225\260\347\273\204\344\273\245\345\217\212\346\214\207\345\220\221\346\214\207\351\222\210\347\232\204\346\214\207\351\222\210/pointers_array.json" new file mode 100644 index 0000000000000000000000000000000000000000..9d43ebfb7530a7691fac88bddb48630ab6b1ec0b --- /dev/null +++ "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/5.\346\214\207\351\222\210\346\225\260\347\273\204\344\273\245\345\217\212\346\214\207\345\220\221\346\214\207\351\222\210\347\232\204\346\214\207\351\222\210/pointers_array.json" @@ -0,0 +1,6 @@ +{ + "type": "code_options", + "author": "卢昕", + "source": "pointers_array.md", + "exercise_id":"7c21ed88658c4513a24afbc96d043028" +} \ No newline at end of file diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/5.\346\214\207\351\222\210\346\225\260\347\273\204\344\273\245\345\217\212\346\214\207\345\220\221\346\214\207\351\222\210\347\232\204\346\214\207\351\222\210/pointers_array.md" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/5.\346\214\207\351\222\210\346\225\260\347\273\204\344\273\245\345\217\212\346\214\207\345\220\221\346\214\207\351\222\210\347\232\204\346\214\207\351\222\210/pointers_array.md" new file mode 100644 index 0000000000000000000000000000000000000000..cedcb0f3787a47926c78de9f16a7af367ce70b2c --- /dev/null +++ "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/5.\346\214\207\351\222\210\346\225\260\347\273\204\344\273\245\345\217\212\346\214\207\345\220\221\346\214\207\351\222\210\347\232\204\346\214\207\351\222\210/pointers_array.md" @@ -0,0 +1,103 @@ +# 打印字符串数组中的所有词 + +给定一个字符串数组,打印数组中的所有词。请选出错误答案。 + +## 答案 +```c +#include +#define LEN 5 + +int main() +{ + char *fruits[LEN] = { + "apple", + "cherry", + "grape", + "peach", + "watermelon" + }; + + for (int i = 0; i < LEN; ++fruits, ++i) + { + printf("%s\n", *fruits); + } + + return 0; +} +``` + +## 选项 +### A +```c +#include +#define LEN 5 + +int main() +{ + char *fruits[LEN] = { + "apple", + "cherry", + "grape", + "peach", + "watermelon" + }; + + for (int i = 0; i < LEN; ++i) + { + printf("%s\n", fruits[i]); + } + + return 0; +} +``` + +### B +```c +#include +#define LEN 5 + +int main() +{ + char *fruits[LEN] = { + "apple", + "cherry", + "grape", + "peach", + "watermelon" + }; + + char **ptr = fruits; + for (int i = 0; i < LEN; ++ptr, ++i) + { + printf("%s\n", *ptr); + } + + return 0; +} +``` + +### C +```c +#include +#define LEN 5 + +int main() +{ + char *fruits[LEN] = { + "apple", + "cherry", + "grape", + "peach", + "watermelon" + }; + + for (int i = 0; i < LEN; ++i) + { + for (int j = 0; fruits[i][j] != '\0'; ++j) + printf("%c", *(*(fruits + i) + j)); + printf("\n"); + } + + return 0; +} +``` diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/7.\346\214\207\345\220\221\345\207\275\346\225\260\347\232\204\346\214\207\351\222\210/config.json" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/6.\346\214\207\345\220\221\345\207\275\346\225\260\347\232\204\346\214\207\351\222\210/config.json" similarity index 100% rename from "data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/7.\346\214\207\345\220\221\345\207\275\346\225\260\347\232\204\346\214\207\351\222\210/config.json" rename to "data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/6.\346\214\207\345\220\221\345\207\275\346\225\260\347\232\204\346\214\207\351\222\210/config.json" diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/7.\346\214\207\345\220\221\345\207\275\346\225\260\347\232\204\346\214\207\351\222\210/pointers_2_func.c" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/6.\346\214\207\345\220\221\345\207\275\346\225\260\347\232\204\346\214\207\351\222\210/pointers_2_func.c" similarity index 100% rename from "data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/7.\346\214\207\345\220\221\345\207\275\346\225\260\347\232\204\346\214\207\351\222\210/pointers_2_func.c" rename to "data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/6.\346\214\207\345\220\221\345\207\275\346\225\260\347\232\204\346\214\207\351\222\210/pointers_2_func.c" diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/7.\346\214\207\345\220\221\345\207\275\346\225\260\347\232\204\346\214\207\351\222\210/pointers_2_func.json" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/6.\346\214\207\345\220\221\345\207\275\346\225\260\347\232\204\346\214\207\351\222\210/pointers_2_func.json" similarity index 100% rename from "data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/7.\346\214\207\345\220\221\345\207\275\346\225\260\347\232\204\346\214\207\351\222\210/pointers_2_func.json" rename to "data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/6.\346\214\207\345\220\221\345\207\275\346\225\260\347\232\204\346\214\207\351\222\210/pointers_2_func.json" diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/7.\346\214\207\345\220\221\345\207\275\346\225\260\347\232\204\346\214\207\351\222\210/pointers_2_func.md" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/6.\346\214\207\345\220\221\345\207\275\346\225\260\347\232\204\346\214\207\351\222\210/pointers_2_func.md" similarity index 100% rename from "data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/7.\346\214\207\345\220\221\345\207\275\346\225\260\347\232\204\346\214\207\351\222\210/pointers_2_func.md" rename to "data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/6.\346\214\207\345\220\221\345\207\275\346\225\260\347\232\204\346\214\207\351\222\210/pointers_2_func.md" diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/6.\346\214\207\351\222\210\346\225\260\347\273\204\344\273\245\345\217\212\346\214\207\345\220\221\346\214\207\351\222\210\347\232\204\346\214\207\351\222\210/config.json" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/6.\346\214\207\351\222\210\346\225\260\347\273\204\344\273\245\345\217\212\346\214\207\345\220\221\346\214\207\351\222\210\347\232\204\346\214\207\351\222\210/config.json" deleted file mode 100644 index 57fc5bddbc442b64a863db7aa0d19a90b6f40e97..0000000000000000000000000000000000000000 --- "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/3.\346\214\207\351\222\210/6.\346\214\207\351\222\210\346\225\260\347\273\204\344\273\245\345\217\212\346\214\207\345\220\221\346\214\207\351\222\210\347\232\204\346\214\207\351\222\210/config.json" +++ /dev/null @@ -1,9 +0,0 @@ -{ - "node_id": "569d5e11c4fc5de7844053d9a733c5e8", - "keywords": [ - "指针", - "C语言" - ], - "children": [], - "export": [] -} \ No newline at end of file diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/4.\345\255\227\347\254\246\344\270\262/1.\345\255\227\347\254\246\344\270\262\350\276\223\345\205\245\344\270\216\350\276\223\345\207\272/config.json" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/4.\345\255\227\347\254\246\344\270\262/1.\345\255\227\347\254\246\344\270\262\350\276\223\345\205\245\344\270\216\350\276\223\345\207\272/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..97e5584d8e1c89b12cf0505a7d671af5bb915231 --- /dev/null +++ "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/4.\345\255\227\347\254\246\344\270\262/1.\345\255\227\347\254\246\344\270\262\350\276\223\345\205\245\344\270\216\350\276\223\345\207\272/config.json" @@ -0,0 +1,9 @@ +{ + "keywords": [ + "C语言概述", + "概述", + "C语言" + ], + "children": [], + "export": ["string_io.json"] +} \ No newline at end of file diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/4.\345\255\227\347\254\246\344\270\262/1.\345\255\227\347\254\246\344\270\262\350\276\223\345\205\245\344\270\216\350\276\223\345\207\272/string_io.c" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/4.\345\255\227\347\254\246\344\270\262/1.\345\255\227\347\254\246\344\270\262\350\276\223\345\205\245\344\270\216\350\276\223\345\207\272/string_io.c" new file mode 100644 index 0000000000000000000000000000000000000000..2498d344ccb9ebb6bcb99af5b9a5947f37741077 --- /dev/null +++ "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/4.\345\255\227\347\254\246\344\270\262/1.\345\255\227\347\254\246\344\270\262\350\276\223\345\205\245\344\270\216\350\276\223\345\207\272/string_io.c" @@ -0,0 +1,32 @@ +#include +#define STR_LEN 101 + +void reverse(char *str) +{ + char* head = str; + char* tail = str; + char ch; + + while(*tail++); + tail -= 2; + + while(head < tail) + { + ch = *head; + *head++ = *tail; + *tail-- = ch; + } +} + +int main() +{ + char str[STR_LEN]; + char *rev_str = NULL; + fputc("请输入一个字符串(length<=100):", stdout); + fgetc(str); + reverse(str); + fputc("反转后的字符串为:", stdout); + fputc(str, stdout); + + return 0; +} \ No newline at end of file diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/4.\345\255\227\347\254\246\344\270\262/1.\345\255\227\347\254\246\344\270\262\350\276\223\345\205\245\344\270\216\350\276\223\345\207\272/string_io.json" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/4.\345\255\227\347\254\246\344\270\262/1.\345\255\227\347\254\246\344\270\262\350\276\223\345\205\245\344\270\216\350\276\223\345\207\272/string_io.json" new file mode 100644 index 0000000000000000000000000000000000000000..050bc6251b8ec3238de022d20d1652a890e82b0c --- /dev/null +++ "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/4.\345\255\227\347\254\246\344\270\262/1.\345\255\227\347\254\246\344\270\262\350\276\223\345\205\245\344\270\216\350\276\223\345\207\272/string_io.json" @@ -0,0 +1,6 @@ +{ + "type": "code_options", + "author": "卢昕", + "source": "string_io.md", + "exercise_id":"228416f6eaa44195810950a1f41de7a4" +} \ No newline at end of file diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/4.\345\255\227\347\254\246\344\270\262/1.\345\255\227\347\254\246\344\270\262\350\276\223\345\205\245\344\270\216\350\276\223\345\207\272/string_io.md" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/4.\345\255\227\347\254\246\344\270\262/1.\345\255\227\347\254\246\344\270\262\350\276\223\345\205\245\344\270\216\350\276\223\345\207\272/string_io.md" new file mode 100644 index 0000000000000000000000000000000000000000..1ad84aeb1c18657dfec0b606e8d0a5d6edfe775e --- /dev/null +++ "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/4.\345\255\227\347\254\246\344\270\262/1.\345\255\227\347\254\246\344\270\262\350\276\223\345\205\245\344\270\216\350\276\223\345\207\272/string_io.md" @@ -0,0 +1,147 @@ +# 字符串输入与输出 + +输入一个字符串,并反向输出。请选出错误答案。 + +## 答案 +```c +#include +#define STR_LEN 101 + +void reverse(char *str) +{ + char* head = str; + char* tail = str; + char ch; + + while(*tail++); + tail -= 2; + + while(head < tail) + { + ch = *head; + *head++ = *tail; + *tail-- = ch; + } +} + +int main() +{ + char str[STR_LEN]; + char *rev_str = NULL; + fputc("请输入一个字符串(length<=100):", stdout); + fgetc(str); + reverse(str); + fputc("反转后的字符串为:", stdout); + fputc(str, stdout); + + return 0; +} +``` + +## 选项 +### A +```c +#include +#define STR_LEN 101 + +void reverse(char *str) +{ + char* head = str; + char* tail = str; + char ch; + + while(*tail++); + tail -= 2; + + while(head < tail) + { + ch = *head; + *head++ = *tail; + *tail-- = ch; + } +} + +int main() +{ + char str[STR_LEN]; + char *rev_str = NULL; + puts("请输入一个字符串(length<=100):"); + gets(str); + reverse(str); + puts("反转后的字符串为:"); + puts(str); + + return 0; +} +``` + +### B +```c +#include +#define STR_LEN 101 + +void reverse(char *str) +{ + char* head = str; + char* tail = str; + char ch; + + while(*tail++); + tail -= 2; + + while(head < tail) + { + ch = *head; + *head++ = *tail; + *tail-- = ch; + } +} + +int main() +{ + char str[STR_LEN]; + char *rev_str = NULL; + printf("请输入一个字符串(length<=100):\n"); + scanf("%s", str); + reverse(str); + printf("反转后的字符串为:\n%s", str); + + return 0; +} +``` + +### C +```c +#include +#define STR_LEN 101 + +void reverse(char *str) +{ + char* head = str; + char* tail = str; + char ch; + + while(*tail++); + tail -= 2; + + while(head < tail) + { + ch = *head; + *head++ = *tail; + *tail-- = ch; + } +} + +int main() +{ + char str[STR_LEN]; + char *rev_str = NULL; + fputs("请输入一个字符串(length<=100):\n", stdout); + fgets(str, STR_LEN, stdin); + reverse(str); + fputs("反转后的字符串为:", stdout); + fputs(str, stdout); + + return 0; +} +``` diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/4.\345\255\227\347\254\246\344\270\262/2.\345\255\227\347\254\246\344\270\262\345\207\275\346\225\260/config.json" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/4.\345\255\227\347\254\246\344\270\262/2.\345\255\227\347\254\246\344\270\262\345\207\275\346\225\260/config.json" new file mode 100644 index 0000000000000000000000000000000000000000..6183b55ded554da53340fe24c658490a1b3d7546 --- /dev/null +++ "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/4.\345\255\227\347\254\246\344\270\262/2.\345\255\227\347\254\246\344\270\262\345\207\275\346\225\260/config.json" @@ -0,0 +1,11 @@ +{ + "keywords": [ + "C语言概述", + "概述", + "C语言" + ], + "children": [], + "export": [ + "string_func.json" + ] +} \ No newline at end of file diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/4.\345\255\227\347\254\246\344\270\262/2.\345\255\227\347\254\246\344\270\262\345\207\275\346\225\260/string_func.c" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/4.\345\255\227\347\254\246\344\270\262/2.\345\255\227\347\254\246\344\270\262\345\207\275\346\225\260/string_func.c" new file mode 100644 index 0000000000000000000000000000000000000000..5adf94af744882301dee9fe2ab58d020e14d0d25 --- /dev/null +++ "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/4.\345\255\227\347\254\246\344\270\262/2.\345\255\227\347\254\246\344\270\262\345\207\275\346\225\260/string_func.c" @@ -0,0 +1,31 @@ +#include +#include +#define SENT_LEN 5 +#define WORDS_NUM 2 +#define STR_LEN 101 + +int main() +{ + int i, j; + char words[SENT_LEN][STR_LEN] = {"非", "淡泊", "无以", "明志", "!"}; + char source[WORDS_NUM][STR_LEN] = {"淡泊", "明志"}; + char target[WORDS_NUM][STR_LEN] = {"宁静", "致远"}; + const char sentence_before[STR_LEN]; + const char sentence_after[STR_LEN]; + + for (i = 0; i < SENT_LEN; ++i) + { + strcat(sentence_before, words[i]); + for (j = 0; j < WORDS_NUM; ++j) + if (strcmp(words[i], source[j]) == 0) + strcpy(words[i], target[j]); + strcat(sentence_after, words[i]); + } + + puts("替换前:"); + puts(sentence_before); + puts("替换后:"); + puts(sentence_after); + + return 0; +} \ No newline at end of file diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/4.\345\255\227\347\254\246\344\270\262/2.\345\255\227\347\254\246\344\270\262\345\207\275\346\225\260/string_func.json" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/4.\345\255\227\347\254\246\344\270\262/2.\345\255\227\347\254\246\344\270\262\345\207\275\346\225\260/string_func.json" new file mode 100644 index 0000000000000000000000000000000000000000..1df5d60afeeeea7bdda9a7d914dc7f2c90f697b6 --- /dev/null +++ "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/4.\345\255\227\347\254\246\344\270\262/2.\345\255\227\347\254\246\344\270\262\345\207\275\346\225\260/string_func.json" @@ -0,0 +1,6 @@ +{ + "type": "code_options", + "author": "卢昕", + "source": "string_func.md", + "exercise_id":"20a63ce313e241a49b6d7ccd2eb1d9e2" +} \ No newline at end of file diff --git "a/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/4.\345\255\227\347\254\246\344\270\262/2.\345\255\227\347\254\246\344\270\262\345\207\275\346\225\260/string_func.md" "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/4.\345\255\227\347\254\246\344\270\262/2.\345\255\227\347\254\246\344\270\262\345\207\275\346\225\260/string_func.md" new file mode 100644 index 0000000000000000000000000000000000000000..0f5a32e0f2438fb89d0f010da46fdd07fae58dfc --- /dev/null +++ "b/data/2.C\350\257\255\350\250\200\344\270\255\351\230\266/4.\345\255\227\347\254\246\344\270\262/2.\345\255\227\347\254\246\344\270\262\345\207\275\346\225\260/string_func.md" @@ -0,0 +1,154 @@ +# 字符串函数的使用 + +比较词序列,并替换其中的指定词,最后将所有词拼接形成一个新的句子。输出如下: +> 替换前: +> +> 非淡泊无以明志! +> +> 替换后: +> +> 非宁静无以致远! +> +请选出正确答案。 + + +## 答案 +```c +#include +#include +#define SENT_LEN 5 +#define WORDS_NUM 2 +#define STR_LEN 101 + +int main() +{ + int i, j; + char words[SENT_LEN][STR_LEN] = {"非", "淡泊", "无以", "明志", "!"}; + char source[WORDS_NUM][STR_LEN] = {"淡泊", "明志"}; + char target[WORDS_NUM][STR_LEN] = {"宁静", "致远"}; + char sentence_before[STR_LEN]; + char sentence_after[STR_LEN]; + + for (i = 0; i < SENT_LEN; ++i) + { + strcat(sentence_before, words[i]); + for (j = 0; j < WORDS_NUM; ++j) + if (strcmp(words[i], source[j]) == 0) + strcpy(words[i], target[j]); + strcat(sentence_after, words[i]); + } + + puts("替换前:"); + puts(sentence_before); + puts("替换后:"); + puts(sentence_after); + + return 0; +} +``` + +## 选项 +### A +```c +#include +#include +#define SENT_LEN 5 +#define WORDS_NUM 2 +#define STR_LEN 101 + +int main() +{ + int i, j; + char words[SENT_LEN][STR_LEN] = {"非", "淡泊", "无以", "明志", "!"}; + char source[WORDS_NUM][STR_LEN] = {"淡泊", "明志"}; + char target[WORDS_NUM][STR_LEN] = {"宁静", "致远"}; + char sentence_before[STR_LEN]; + char sentence_after[STR_LEN]; + + for (i = 0; i < SENT_LEN; ++i) + { + strcat(sentence_before, words[i]); + for (j = 0; j < WORDS_NUM; ++j) + if (strcmp(words[i], source[j]) >= 0) + strcpy(words[i], target[j]); + strcat(sentence_after, words[i]); + } + + puts("替换前:"); + puts(sentence_before); + puts("替换后:"); + puts(sentence_after); + + return 0; +} +``` + +### B +```c +#include +#include +#define SENT_LEN 5 +#define WORDS_NUM 2 +#define STR_LEN 101 + +int main() +{ + int i, j; + char* words[SENT_LEN] = {"非", "淡泊", "无以", "明志", "!"}; + char* source[WORDS_NUM] = {"淡泊", "明志"}; + char* target[WORDS_NUM] = {"宁静", "致远"}; + char sentence_before[STR_LEN]; + char sentence_after[STR_LEN]; + + for (i = 0; i < SENT_LEN; ++i) + { + strcat(sentence_before, words[i]); + for (j = 0; j < WORDS_NUM; ++j) + if (strcmp(words[i], source[j]) == 0) + strcpy(words[i], target[j]); + strcat(sentence_after, words[i]); + } + + puts("替换前:"); + puts(sentence_before); + puts("替换后:"); + puts(sentence_after); + + return 0; +} +``` + +### C +```c +#include +#include +#define SENT_LEN 5 +#define WORDS_NUM 2 +#define STR_LEN 101 + +int main() +{ + int i, j; + char words[SENT_LEN][STR_LEN] = {"非", "淡泊", "无以", "明志", "!"}; + char source[WORDS_NUM][STR_LEN] = {"淡泊", "明志"}; + char target[WORDS_NUM][STR_LEN] = {"宁静", "致远"}; + const char sentence_before[STR_LEN]; + const char sentence_after[STR_LEN]; + + for (i = 0; i < SENT_LEN; ++i) + { + strcat(sentence_before, words[i]); + for (j = 0; j < WORDS_NUM; ++j) + if (strcmp(words[i], source[j]) == 0) + strcpy(words[i], target[j]); + strcat(sentence_after, words[i]); + } + + puts("替换前:"); + puts(sentence_before); + puts("替换后:"); + puts(sentence_after); + + return 0; +} +```