随笔分类 -  c/c++

上一页 1 ··· 13 14 15 16 17 18 19 20 21 ··· 30 下一页
摘要: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 阅读(57) 评论(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 阅读(55) 评论(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 阅读(1311) 评论(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 阅读(78) 评论(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 阅读(116) 评论(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 阅读(138) 评论(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 阅读(92) 评论(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 阅读(78) 评论(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 阅读(61) 评论(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 阅读(2564) 评论(0) 推荐(0)
摘要:1、 #include <stdio.h> #define swap(type, x, y) type tmp = x; x = y; y = tmp; int main(void) { int x = 10, y = 5; swap(int, x, y); printf("x = %d\n", x 阅读全文
posted @ 2021-05-24 18:39 小鲨鱼2018 阅读(60) 评论(0) 推荐(0)
摘要:1、 #include <stdio.h> #define max(x, y) ((x > y) ? x : y) int main(void) { int a, b, c, d; puts("please input four integers."); printf("a = "); scanf( 阅读全文
posted @ 2021-05-24 18:29 小鲨鱼2018 阅读(89) 评论(0) 推荐(0)
摘要:c语言 8-1 1、 #include <stdio.h> #define diff(x, y) ((x) - (y)) int main(void) { int a, b; puts("please input two integers."); printf("a = "); scanf("%d" 阅读全文
posted @ 2021-05-24 18:09 小鲨鱼2018 阅读(387) 评论(0) 推荐(0)
摘要:c语言中函数、函数式宏例子 返回一个数的平方。 1、函数 #include <stdio.h> int sqr_int(int x) { return x * x; } double sqr_double(double x) { return x * x; } int main(void) { in 阅读全文
posted @ 2021-05-24 13:07 小鲨鱼2018 阅读(232) 评论(0) 推荐(0)
摘要:1、 #include <stdio.h> int main(void) { int i, j, ch; int cnt[10] = {}; while((ch = getchar()) != EOF) { if(ch > '0' && ch < '9') { cnt[ch - '0']++; } 阅读全文
posted @ 2021-05-24 12:20 小鲨鱼2018 阅读(118) 评论(0) 推荐(0)
摘要:c语言中数字字符计数 1、 #include <stdio.h> int main(void) { int i, ch; int cnt[10] = {}; while((ch = getchar()) != EOF) { switch(ch) { case '0': cnt[0]++; break 阅读全文
posted @ 2021-05-24 10:54 小鲨鱼2018 阅读(564) 评论(0) 推荐(0)
摘要:1、 #include <stdio.h> int main(void) { int ch; int rows = 0; while((ch = getchar()) != EOF) { switch(ch) { case '\n': rows++; break; } } printf("numbe 阅读全文
posted @ 2021-05-24 09:10 小鲨鱼2018 阅读(65) 评论(0) 推荐(0)
摘要:c语言中数字字符计数。 1、 #include <stdio.h> int main(void) { int i, ch; int cnt[10] = {}; while((ch = getchar()) != EOF) { switch(ch) { case '0': cnt[0]++; brea 阅读全文
posted @ 2021-05-23 23:09 小鲨鱼2018 阅读(473) 评论(0) 推荐(0)
摘要:c语言中将输入的字符直接输出 getchar函数 和EOF getchar函数用于读取字符并返回,(getchar和putchar都只处理一个字符); EOF是对象式宏,为一个负值。 1、 #include <stdio.h> int main(void) { int ch; while((ch = 阅读全文
posted @ 2021-05-23 22:33 小鲨鱼2018 阅读(1211) 评论(0) 推荐(0)
摘要:1、 #include <stdio.h> int main(void) { int ch; int time[1] = {}; while((ch = getchar()) != EOF) { switch(ch) { case '\n': time[0]++; break; } } printf 阅读全文
posted @ 2021-05-23 11:31 小鲨鱼2018 阅读(63) 评论(0) 推荐(0)

上一页 1 ··· 13 14 15 16 17 18 19 20 21 ··· 30 下一页