摘要: 1、线性查找法 #include <stdio.h> #define FAILED -1 int len(char x[]) { int len = 0; while(x[len]) len++; return len; } int search(char x[], char key) { int 阅读全文
posted @ 2021-05-25 23:02 小鲨鱼2018 阅读(46) 评论(0) 推荐(0) 编辑
摘要: 1、 #include <stdio.h> void null_string(char x[]) { x[0] = '\0'; } int main(void) { char str[128]; printf("str: "); scanf("%s", str); printf("begin: %s 阅读全文
posted @ 2021-05-25 22:10 小鲨鱼2018 阅读(48) 评论(0) 推荐(0) 编辑
摘要: c语言中输出字符串的长度。 1、 #include <stdio.h> int str_len(const char x[]) { int len = 0; while(x[len]) len++; return len; } int main(void) { char str[100]; prin 阅读全文
posted @ 2021-05-25 21:56 小鲨鱼2018 阅读(1236) 评论(0) 推荐(0) 编辑
摘要: 1、 #include <stdio.h> #define NUMBER 10 int main(void) { int i; char s[NUMBER][128]; for(i = 0; i < NUMBER; i++) { printf("s[%d] = ", i); scanf("%s", 阅读全文
posted @ 2021-05-25 21:10 小鲨鱼2018 阅读(57) 评论(0) 推荐(0) 编辑
摘要: 1、 #include <stdio.h> int main(void) { char s[] = "ABC"; printf("begin: %s\n", s); int i; for(i = 0; i < 4; i++) { s[i] = '\0'; } printf("end: %s\n", 阅读全文
posted @ 2021-05-25 18:26 小鲨鱼2018 阅读(99) 评论(0) 推荐(0) 编辑
摘要: 字符串字面量的中间也可以有null字符,不过应注意区分。字符串字面量“ABC”是字符串,而字符串字面量“AB\0CD”不是字符串。 1、 #include <stdio.h> int main(void) { char str[] = "ABC\0DEF"; printf("result: %s.\ 阅读全文
posted @ 2021-05-25 18:08 小鲨鱼2018 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 1、 #include <stdio.h> int gcd(int x, int y) { int max, min, tmp; max = x > y ? x : y; min = x > y ? y : x; tmp = x % y; if(tmp != 0) { gcd(min, tmp); 阅读全文
posted @ 2021-05-25 12:58 小鲨鱼2018 阅读(82) 评论(0) 推荐(0) 编辑
摘要: 1、 #include <stdio.h> int fac(int x) { if(x > 0) return x * fac(x - 1); else return 1; } int main(void) { int n, r; puts("please input two integers.") 阅读全文
posted @ 2021-05-25 11:40 小鲨鱼2018 阅读(68) 评论(0) 推荐(0) 编辑
摘要: 1、 #include <stdio.h> enum a {x, y, z}; int main(void) { printf("x = %d\n", x); printf("y = %d\n", y); printf("z = %d\n", z); return 0; } 2、 #include 阅读全文
posted @ 2021-05-25 09:39 小鲨鱼2018 阅读(47) 评论(0) 推荐(0) 编辑
摘要: 1、从尾至头,升序 #include <stdio.h> #define NUMBER 5 void sort_1(int x[], int n) { int i, j; for(i = 0; i < n - 1; i++) { for(j = n - 1; j > i; j--) { if(x[j 阅读全文
posted @ 2021-05-25 08:44 小鲨鱼2018 阅读(2460) 评论(0) 推荐(0) 编辑