diff --git a/day6/a.out b/day6/a.out new file mode 100755 index 0000000..8ec30d0 Binary files /dev/null and b/day6/a.out differ diff --git a/day6/d12.c b/day6/d12.c new file mode 100644 index 0000000..7d1ed2b --- /dev/null +++ b/day6/d12.c @@ -0,0 +1,19 @@ +#include + +int main() +{ + char teacher[] = {'d', 'i', 's', 'e', 'n'}; + printf("%s\n", teacher); // disen + int len = sizeof(teacher); + printf("%d\n", len); // 5 + // for (int i = 0; i < len; i++) + // { + // printf("%c", teacher[i]); + // } + int i = 0; + while (i < len) + { + printf("%c", teacher[i++]); + } + return 0; +} \ No newline at end of file diff --git a/day6/d13.c b/day6/d13.c new file mode 100644 index 0000000..417db80 --- /dev/null +++ b/day6/d13.c @@ -0,0 +1,18 @@ +#include +#include + +int main() +{ + char ask_name[32] = "Jack"; // 结果是 "Jack\0" + printf("%s\n", ask_name); + // sizeof() 统计变量或数组实际分配的内存空间大小,单位是字节 + printf("ask_name size is %ldB\n", sizeof(ask_name)); + // strlen() 函数统计有效的字符个数,不包括 '\0' (遇到第一个 '\0' 就停止统计 ) + printf("ask_name char len is %ld\n", strlen(ask_name)); + + char q_what1[128] = "hi,xiao hua\0,love you!"; + printf("%s\n", q_what1); + printf("%ld \n", strlen(q_what1)); + + return 0; +} \ No newline at end of file diff --git a/day6/d14.c b/day6/d14.c new file mode 100644 index 0000000..f0ca0a1 --- /dev/null +++ b/day6/d14.c @@ -0,0 +1,23 @@ +#include + +int main() +{ + char arr[64] = "hi, disen!"; + // 实现 strlen() 的功能, 统计字符串的长度 + int i = 0; + while (arr[i]) + i++; + printf("%s length: %d\n", arr, i); + + // 反转字符串 + int j = 0; + int mid = i >> 1; // 含义: i / 2, 位运算更快 + while (j < mid) + { + arr[j] ^= arr[i - j - 1]; + arr[i - j - 1] ^= arr[j]; + arr[j] ^= arr[i - j - 1]; + j++; + } + printf("%s\n", arr); +} \ No newline at end of file diff --git a/day6/d15.c b/day6/d15.c new file mode 100644 index 0000000..ded73fb --- /dev/null +++ b/day6/d15.c @@ -0,0 +1,20 @@ +#include +#include + +int main() +{ + char cmd[32] = ""; + printf("请输入一个命令:"); + // scanf() 输入字符串是,遇到第一个空格就停止输入 + // scanf("%s", cmd); // cmd 数组传递的是地址, 不需要加 & 取地址符 + + fgets(cmd, sizeof(cmd), stdin); // 读取一行字符串,遇到回车就停止输入 + // fgets() 获取的字符最后一个是 '\n' 换行符 + cmd[strlen(cmd) - 1] = 0; // 将最后一个字符 '\n' 换成 '\0' 空字符 + + // printf("%s \n", cmd); + // for (int i = 0; i < 32; i++) + printf("%s, %ld\n", cmd, strlen(cmd)); + printf("\n"); + return 0; +} \ No newline at end of file diff --git a/day6/d17.c b/day6/d17.c new file mode 100644 index 0000000..1e190a4 --- /dev/null +++ b/day6/d17.c @@ -0,0 +1,25 @@ +#include +#include + +int main() +{ + // char stu_names[5][32] = {"zhangsan", "lisi", "wangwu", "zhaoliu", "tianqi"}; + char stu_names[5][32]; + int i = 0; + while (i < 5) + { + printf("请输入第 %d 个学生的名字:", i + 1); + fgets(stu_names[i], sizeof(stu_names[i]), stdin); + + stu_names[i][strlen(stu_names[i]) - 1] = '\0'; + + i++; + } + + for (int i = 0; i < 5; i++) + { + printf("%s\n", stu_names[i]); + } + + return 0; +} \ No newline at end of file diff --git a/day6/d18.c b/day6/d18.c new file mode 100644 index 0000000..a2da580 --- /dev/null +++ b/day6/d18.c @@ -0,0 +1,2 @@ +#include +#include diff --git a/day6/d19.c b/day6/d19.c new file mode 100644 index 0000000..cf7fbaa --- /dev/null +++ b/day6/d19.c @@ -0,0 +1,6 @@ +#include +#include + +int main() +{ +} \ No newline at end of file diff --git a/day6/d6.c b/day6/d6.c new file mode 100644 index 0000000..dba1dce --- /dev/null +++ b/day6/d6.c @@ -0,0 +1,33 @@ +#include + +int main() +{ + int nums[5][3] = {0}; + int n; + for (int i = 0; i < 5; i++) + { + printf("请输入第%d个三位数:", i + 1); + scanf("%d", &n); + + int m[] = {100, 10, 1}; + int j = 0; + while (n > 0) + { + nums[i][j] = n / m[j]; + n %= m[j]; + j++; + } + } + + for (int i = 0; i < 5; i++) + { + // 判断这个三位数是否为回文数 + if (nums[i][0] == nums[i][2]) + continue; + for (int j = 0; j < 3; j++) + { + printf("%d ", nums[i][j]); + } + printf("\n"); + } +}