05 2021 档案

摘要:1、函数原型。 #include <stdio.h> char *strncat(char *s1, const char *s2, size_t n) // 这里的cat指的是:concatenate { char *tmp = s1; while(*s1) s1++; while(n--) if 阅读全文
posted @ 2021-05-31 22:59 小鲨鱼2018 阅读(427) 评论(0) 推荐(0) 编辑
摘要:c语言中strcat函数。 1、函数原型。 #include <stdio.h> char *strcat(char *s1, const char *s2) { char *tmp = s1; while(*s1) s1++; while(*s1++ = *s2++) ; return tmp; 阅读全文
posted @ 2021-05-31 22:26 小鲨鱼2018 阅读(850) 评论(0) 推荐(0) 编辑
摘要:1、函数原型。 #include <stdio.h> char *strncpy(char *s1, const char *s2, size_t n) { char *tmp = s1; while(n) { if(!(*s1++ = *s2++)) break; n--; } while(n-- 阅读全文
posted @ 2021-05-31 21:52 小鲨鱼2018 阅读(642) 评论(0) 推荐(0) 编辑
摘要:c语言中字符串的复制。 1、自定义函数 #include <stdio.h> char *str_copy(char *d, char *s) { char *t = d; while(*d++ = *s++) ; return t; } int main(void) { char str[128] 阅读全文
posted @ 2021-05-31 21:08 小鲨鱼2018 阅读(1207) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> char *str_chr(char *x, int key) { while(*x) { if(*x == key) { char *t = x; return t; } x++; } return NULL; } int main(void) { ch 阅读全文
posted @ 2021-05-31 20:09 小鲨鱼2018 阅读(46) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> int str_c(const char *x, int key) { int j = 0; while(*x) { if(*x == key) j++; x++; } return j; } int main(void) { char str[128]; 阅读全文
posted @ 2021-05-31 19:24 小鲨鱼2018 阅读(38) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> void put_string(const char *s) // 传入的实参为指针,在数组中,指向首个字符的指针的行为和数组本身一样。 { printf("%s\n", s); // 显示数组本身。 } int main(void) { char str 阅读全文
posted @ 2021-05-31 16:50 小鲨鱼2018 阅读(64) 评论(0) 推荐(0) 编辑
摘要:1、利用数组。 #include <stdio.h> int len(char x[]) { int len = 0; while(x[len]) len++; return len; } int main(void) { char str[128]; printf("str = "); scanf 阅读全文
posted @ 2021-05-31 16:41 小鲨鱼2018 阅读(471) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> char* copy_str(char *d, const char *s) { char *t = d; while(*d++ = *s++) ; return t; } int main(void) { char str[128] = "ABCD"; 阅读全文
posted @ 2021-05-31 16:15 小鲨鱼2018 阅读(71) 评论(0) 推荐(0) 编辑
摘要:c语言中字符串的复制。 1、 #include <stdio.h> char* str_copy(char *d, const char *s) //函数的返回值为指向char型的指针型, 形参为两个指向char型的指针。 { char *t = d; // 指针t等于指针d,指针d为指向字符串第一 阅读全文
posted @ 2021-05-31 16:02 小鲨鱼2018 阅读(912) 评论(0) 推荐(0) 编辑
摘要:c语言中利用数组、指针实现字符串、字符串数组。 1、字符串 #include <stdio.h> int main(void) { char x[] = "abcd"; //数组实现字符串 ,x一般解释为指向数组第一个元素的指针 char *y = "xyz"; //指针实现字符串 ,y为指向一个字 阅读全文
posted @ 2021-05-31 11:13 小鲨鱼2018 阅读(734) 评论(0) 推荐(0) 编辑
摘要:c语言中显示字符串数组的长度(数组实现的字符串数组和指针实现的字符串数组) 1、 #include <stdio.h> int main(void) { char x[][128] = {"aaa","bb","cccccc","d","eee"}; char *y[] = {"11111","22 阅读全文
posted @ 2021-05-31 11:01 小鲨鱼2018 阅读(770) 评论(0) 推荐(0) 编辑
摘要:c语言中判断字符串的长度,利用数组和利用指针。 1、利用数组。 #include <stdio.h> int len(const char x[]) { int len = 0; while(x[len]) len++; return len; } int main(void) { char str 阅读全文
posted @ 2021-05-31 10:55 小鲨鱼2018 阅读(1855) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> int main(void) { int i; char a[][5] = {"LISP","C","Ada"}; char *p[] = {"PAUL","X","MAC"}; printf("sizeof(a) = %u\n", sizeof(a)); 阅读全文
posted @ 2021-05-31 09:39 小鲨鱼2018 阅读(64) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> int main(void) { int i; char a[][5] = {"LISP","C","Ada"}; char *p[] = {"PAUL","X","MAC"}; int j = 0; while(1) { int k = 0; while 阅读全文
posted @ 2021-05-30 23:33 小鲨鱼2018 阅读(45) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> int main(void) { char *p = "123"; printf("p = %s\n", p); p = "456"; printf("p = %s\n", p); return 0; } ↓ #include <stdio.h> int 阅读全文
posted @ 2021-05-30 22:12 小鲨鱼2018 阅读(48) 评论(0) 推荐(0) 编辑
摘要:用数组实现的字符串和用指针实现的字符串。 1、 #include <stdio.h> int main(void) { char str[] = "abc"; //数组实现的字符串,str为数组名,为指向数组起始元素的指针,相当于“a”的指针。 char *ptr = "123"; //指针实现的字 阅读全文
posted @ 2021-05-30 21:44 小鲨鱼2018 阅读(241) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> void ary_set(int x[], int n, int val) { int i; for(i = 0; i < n; i++) { x[i] = val; } } int main(void) { int i; int a[5] = {1, 2 阅读全文
posted @ 2021-05-30 18:36 小鲨鱼2018 阅读(78) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> void assign1(int x[], int n)//函数间数组的传递是以数组第一个元素的指针的形式传递的,因此形参变为指向数组第一个元素的指针,形参和数组本身的行为一样。 { int i; for(i = 0; i < n; i++) { x[i] 阅读全文
posted @ 2021-05-30 18:27 小鲨鱼2018 阅读(81) 评论(0) 推荐(0) 编辑
摘要:1、函数间数组的传递是以指向第一个元素的指针的形式进行的,应为数组名会被解释为指向数组第一个元素的指针,形参部分的指针变量被赋值为数组的第一个元素 的指针时,指针变量指向数组的一个元素,因此指针变量的行为和传入的数组一样。 #include <stdio.h> void assign(int x[] 阅读全文
posted @ 2021-05-30 18:15 小鲨鱼2018 阅读(412) 评论(0) 推荐(0) 编辑
摘要:对于数组a[n], 当p为数组的起始元素的指针时, 即 p = a = &a[0]时, p + i = a[i], &p[i] = &a[i] , a[i] = p[i], *(a + i) = *(p + i), 也就是说当p为数组的起始 元素的指针时,p的行为和数组本身是一样的。(原因: p为数 阅读全文
posted @ 2021-05-30 17:28 小鲨鱼2018 阅读(113) 评论(0) 推荐(0) 编辑
摘要:当指针p声明为数组名a时, 则有 p + i = &a[i], 也就是说p + i是首个元素之后的第i个元素的指针。 1、 #include <stdio.h> int main(void) { int i; int a[5]; int *p = a; for(i = 0; i < 5; i++) 阅读全文
posted @ 2021-05-30 16:59 小鲨鱼2018 阅读(206) 评论(0) 推荐(0) 编辑
摘要:1、三个值升序 #include <stdio.h> void swap(int *x, int *y) { int tmp = *x; *x = *y; *y = tmp; } void sort(int *i, int *j, int *k) { if(*i > *j) swap(i, j); 阅读全文
posted @ 2021-05-30 16:12 小鲨鱼2018 阅读(81) 评论(0) 推荐(0) 编辑
摘要:1、如果小于0,修改为150, 大于100,修改为100 #include <stdio.h> void adjust(int *x) { if(*x < 0) *x = 150; //变量的值作为了下一个判断条件,如何避免? if(*x > 100) *x = 100; } int main(vo 阅读全文
posted @ 2021-05-30 15:57 小鲨鱼2018 阅读(130) 评论(0) 推荐(0) 编辑
摘要:在c语言程序中,指针的一个重要作用就是作为函数的参数。 001:指针作为参数可以解决对传入到函数中的变量进行修改的目的。 如果要在函数中修改变量的值,就需要传入该变量的指针,然后再函数体中使用指针运算符,这样就获取了原始对象的别名,在函数体中对别名进行修改,就相当于对原始对象进行修改。 间接访问运算 阅读全文
posted @ 2021-05-30 13:30 小鲨鱼2018 阅读(1054) 评论(0) 推荐(0) 编辑
摘要:1、c语言中函数的参数 01、c语言中实参向形参的传递过程是单向传递的,在对形参进行修改后的值不能返回给实参。 02、函数返回调用源的返回值只能有一个。 例、求两个数的和与差。 #include <stdio.h> void sum_diff(int x, int y, int sum, int d 阅读全文
posted @ 2021-05-30 12:12 小鲨鱼2018 阅读(1419) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> void ary_set(int v[], int n, int val) { int i; for(i = 0; i < n; i++) { v[i] = val; } } int main(void) { int i; int a[5] = {1,2, 阅读全文
posted @ 2021-05-30 09:22 小鲨鱼2018 阅读(113) 评论(0) 推荐(0) 编辑
摘要:函数间数组的传递,是以指向第一个元素的指针的形式进行的。 在被调用的函数中作为指针接收的数组, 实际上就是调用方传递的数组。 Type*型指针p指向Type型数组a的起始元素a[0]时, 指针p的行为就和数组a本身一样。 值: a[i] = *(a + i) = *(p + i) = p[i]; 指 阅读全文
posted @ 2021-05-30 08:32 小鲨鱼2018 阅读(59) 评论(0) 推荐(0) 编辑
摘要:c语言中指针运算符和下标运算符。 1、对于数组中任一元素 a[i], 一般由三个别名: *(a + i)、*(p + i)、p[i]。 其中p为指向数组第一个元素的指针(p + i 等价于 &a[i])。 对应的指针分别为: &a[i]、 a + i、p + i、&p[i]. 利用程序证明: a[i 阅读全文
posted @ 2021-05-29 22:25 小鲨鱼2018 阅读(1008) 评论(0) 推荐(0) 编辑
摘要:c语言中数组的名称原则上为数组的第一个元素的指针。(当sizeof和&应用数数组名除外)。 当p为第一个元素的指针时, p + i 为第一个元素后的第i个元素的指针,则 p + i等价于 &a[i]. 程序如下: #include <stdio.h> int main(void) { int i; 阅读全文
posted @ 2021-05-29 22:02 小鲨鱼2018 阅读(235) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> void swap2(int *x, int *y) { int tmp; tmp = *x; *x = *y; *y = tmp; } void sort2(int *n1, int *n2, int *n3) { if(*n1 > *n2) //将前两 阅读全文
posted @ 2021-05-29 16:24 小鲨鱼2018 阅读(64) 评论(0) 推荐(0) 编辑
摘要:c语言中两个值的排序,指针在函数间的传递。 1、 #include <stdio.h> void sap(int *x, int *y) { int tmp; tmp = *x; *x = *y; *y = tmp; } void sort2(int *n1, int *n2) // n1和n2为指 阅读全文
posted @ 2021-05-29 14:09 小鲨鱼2018 阅读(201) 评论(0) 推荐(0) 编辑
摘要:1、last day (错误程序) #include <stdio.h> void lastday(int *y, int *m, int *d) { if(*d > 1) { *d -= 1; } if(*d == 1 && *m == 2 || *m == 4 || *m == 6 || *m 阅读全文
posted @ 2021-05-29 12:13 小鲨鱼2018 阅读(97) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> void adjust(int *x) //声明指向int型的指针变量x { if(*x < 0) *x = 0; if(*x > 100) *x = 100; } int main(void) { int a, b, c; puts("please in 阅读全文
posted @ 2021-05-29 10:25 小鲨鱼2018 阅读(72) 评论(0) 推荐(0) 编辑
摘要:c语言中实现两个值互换的函数。 1、 #include <stdio.h> void swap(int n1, int n2) { int tmp; tmp = n1; n1 = n2; n2 = tmp; } int main(void) { int a, b; puts("please inpu 阅读全文
posted @ 2021-05-29 09:55 小鲨鱼2018 阅读(1595) 评论(0) 推荐(0) 编辑
摘要:c语言中作为函数参数的指针。 1、 #include <stdio.h> void fun(int *x) //声明指向int型的指针变量 { if(*x < 200) { *x = 5000; } } int main(void) { int a = 100; int b = 140; int c 阅读全文
posted @ 2021-05-29 09:23 小鲨鱼2018 阅读(428) 评论(0) 推荐(0) 编辑
摘要:c语言中利用函数同时返回两个数的和与差。 1、 #include <stdio.h> void sum_diff(int n1, int n2, int sum, int diff) { sum = n1 + n2; diff = (n1 > n2) ? (n1 - n2) : (n2 - n1); 阅读全文
posted @ 2021-05-29 09:12 小鲨鱼2018 阅读(1036) 评论(0) 推荐(0) 编辑
摘要:1、单目运算符&为取址运算符,其作用是获取对象的地址,生成指向对象的指针,与其说是获取地址,不如说是生成指针。对象地址的转换说明为%p,其中的p为pointer的首字母。 #include <stdio.h> int main(void) { int n; double x; int a[3]; p 阅读全文
posted @ 2021-05-29 08:58 小鲨鱼2018 阅读(1442) 评论(0) 推荐(0) 编辑
摘要:c语言中指针作为参数的函数同时计算两个数的和与差。 1、 #include <stdio.h> void sum_dif(int n1, int n2, int *sum, int *dif) { *sum = n1 + n2; *dif = (n1 > n2) ? (n1 - n2) : (n2 阅读全文
posted @ 2021-05-28 23:13 小鲨鱼2018 阅读(1350) 评论(0) 推荐(0) 编辑
摘要:c语言中将指针作为函数的参数。 1、 #include <stdio.h> void fun(int *x) { if(*x < 170) // 指向特定对象的指针,在使用指针运算符的时候就是该对象的别名,对别名进行重新赋值,可以传递给main函数。 { *x = 1000; } } int mai 阅读全文
posted @ 2021-05-28 22:24 小鲨鱼2018 阅读(390) 评论(0) 推荐(0) 编辑
摘要:c语言中指针 1、 #include <stdio.h> int main(void) { int a = 100; int b = 200; int c = 300; int *x, *y; x = &a; y = &c; printf("xxxx: %d\n", *x); printf("yyy 阅读全文
posted @ 2021-05-28 16:52 小鲨鱼2018 阅读(104) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> void rev(char x[][128], int n) { int i; for(i = 0; i < n; i++) { int len = 0; while(x[i][len]) len++; int j = 0; while(x[i][j]) 阅读全文
posted @ 2021-05-27 19:12 小鲨鱼2018 阅读(60) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> #define NUMBER 5 #define STR 128 void show(char x[][STR], int n) { int i; for(i = 0; i < n; i++) { if(strcmp(x[i], "$$$$$") == 0 阅读全文
posted @ 2021-05-27 18:45 小鲨鱼2018 阅读(35) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> void del(char x[]) { int len = 0; while(x[len]) len++; char tmp[len]; int i = 0, j = 0; while(x[i]) { if(x[i] < '0' || x[i] > '9 阅读全文
posted @ 2021-05-27 17:28 小鲨鱼2018 阅读(79) 评论(0) 推荐(0) 编辑
摘要:c语言中大小写字符转换。 1、 #include <stdio.h> #include <ctype.h> void upper(char x[]) { int i = 0; while(x[i]) { x[i] = toupper(x[i]); i++; } } void lower(char x 阅读全文
posted @ 2021-05-27 17:02 小鲨鱼2018 阅读(1978) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> void put(char x[]) { int len = 0; while(x[len]) len++; int i; for(i = 0; i < len / 2; i++) { int tmp = x[i]; x[i] = x[len - 1 - 阅读全文
posted @ 2021-05-27 16:52 小鲨鱼2018 阅读(51) 评论(0) 推荐(0) 编辑
摘要:c语言中统计字符串中数字出现的次数。 1、 #include <stdio.h> void count(char x[], int y[]) { int i = 0; while(x[i]) { if(x[i] >= '0' && x[i] <= '9') y[x[i] - '0']++; i++; 阅读全文
posted @ 2021-05-27 16:22 小鲨鱼2018 阅读(1404) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> void put(char x[]) { int len = 0; while(x[len]) len++; while(len-- > 0) { putchar(x[len]); } } int main(void) { char str[128]; p 阅读全文
posted @ 2021-05-27 13:03 小鲨鱼2018 阅读(145) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> void put(char x[], int n) { int i; for(i = 0; i < n; i++) { printf("%s", x); } } int main(void) { char str[128]; printf("str: ") 阅读全文
posted @ 2021-05-27 12:51 小鲨鱼2018 阅读(64) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> int str_chnum(char x[], int key) { int len = 0; while(x[len]) len++; int j = 0; while(len-- > 0) { if(x[len] == key) j++; } if(j 阅读全文
posted @ 2021-05-27 12:11 小鲨鱼2018 阅读(58) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> int str_char(char x[], int key) { int len = 0; while(x[len]) len++; int i; for(i = 0; i < len; i++) { if(x[i] == key) return i; 阅读全文
posted @ 2021-05-27 11:25 小鲨鱼2018 阅读(79) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> void null_str(char x[]) { x[0] = '\0'; } int main(void) { char str[128]; printf("str: "); scanf("%s", str); null_str(str); puts( 阅读全文
posted @ 2021-05-27 11:09 小鲨鱼2018 阅读(48) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> #define NUMBER 5 int main(void) { char str[NUMBER][128]; int i; for(i = 0; i < NUMBER; i++) { printf("str[%d] = ", i); scanf("%s 阅读全文
posted @ 2021-05-27 10:14 小鲨鱼2018 阅读(53) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> void rev_str(char x[][128], int n) { int i; for(i = 0; i < n; i++) { int j = 0; while(x[i][j]) j++; while(j-- > 0) putchar(x[i][ 阅读全文
posted @ 2021-05-26 22:07 小鲨鱼2018 阅读(42) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> #define NUMBER 5 #define STR 128 void put(char x[][STR], int n) { int i; for(i = 0; i < n; i++) { if(strcmp(x[i], "$$$$$") == 0) 阅读全文
posted @ 2021-05-26 21:29 小鲨鱼2018 阅读(34) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> void del_dit(char x[]) { int i = 0, j = 0; char tmp[129]; while(x[i]) { if((x[i] - '0') < 0 || (x[i] - '0') > 9) { tmp[j] = x[i] 阅读全文
posted @ 2021-05-26 17:48 小鲨鱼2018 阅读(62) 评论(0) 推荐(0) 编辑
摘要:c语言中实现字符串大小写的转换。 1、 #include <stdio.h> #include <ctype.h> void str_toupper(char x[]) { int i = 0; while(x[i]) { x[i] = toupper(x[i]); i++; } } void st 阅读全文
posted @ 2021-05-26 16:52 小鲨鱼2018 阅读(2393) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> void rev_put(char x[]) { int i, len = 0; while(x[len]) len++; for(i = 0; i < len / 2; i++) { char tmp = x[i]; x[i] = x[len - 1 - 阅读全文
posted @ 2021-05-26 16:34 小鲨鱼2018 阅读(41) 评论(0) 推荐(0) 编辑
摘要:c语言中统计字符串中数字字符出现的次数。 1、 #include <stdio.h> void int_count(char x[], int cnt[]) { int i; while(x[i]) { if(x[i] >= '0' && x[i] <= '9') { cnt[x[i] - '0'] 阅读全文
posted @ 2021-05-26 16:06 小鲨鱼2018 阅读(1917) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> void put(char x[]) { int len = 0; while(x[len]) len++; int i = 0; while(x[i]) { putchar(x[len - 1 - i++]); } putchar('\n'); } in 阅读全文
posted @ 2021-05-26 13:13 小鲨鱼2018 阅读(60) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> void put(char x[], int n) { while(n-- > 0) printf(x); putchar('\n'); } int main(void) { char str[128]; int n; printf("str: "); s 阅读全文
posted @ 2021-05-26 12:34 小鲨鱼2018 阅读(51) 评论(0) 推荐(0) 编辑
摘要:c语言中使用putchar显示字符串 1、 #include <stdio.h> int put(char x[]) { int i = 0; while(x[i]) putchar(x[i++]); } int main(void) { char str[128]; printf("str: ") 阅读全文
posted @ 2021-05-26 12:23 小鲨鱼2018 阅读(419) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> int search(char x[], int c) { int i = 0, j = 0; while(1) { if(x[i] == c) { j++; } if(x[i] == '\0') break; i++; } return j == 0 ? 阅读全文
posted @ 2021-05-26 11:38 小鲨鱼2018 阅读(49) 评论(0) 推荐(0) 编辑
摘要: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 阅读(49) 评论(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 阅读(49) 评论(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 阅读(1297) 评论(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 阅读(64) 评论(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 阅读(107) 评论(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 阅读(132) 评论(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 阅读(86) 评论(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 阅读(71) 评论(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 阅读(50) 评论(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 阅读(2554) 评论(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 阅读(50) 评论(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 阅读(67) 评论(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 阅读(372) 评论(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 阅读(224) 评论(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 阅读(105) 评论(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 阅读(556) 评论(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 阅读(58) 评论(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 阅读(465) 评论(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 阅读(1191) 评论(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 阅读(51) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> int gcd(int x, int y) { int max, min, tmp; if(x != y) { max = x > y ? x : y; min = x > y ? y : x; tmp = max % min; if(tmp != 0) 阅读全文
posted @ 2021-05-22 23:42 小鲨鱼2018 阅读(53) 评论(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 a, b; puts("please input two integers.") 阅读全文
posted @ 2021-05-22 23:22 小鲨鱼2018 阅读(60) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> int fac(int x) { int i, fac = 1; if(x > 0) { for(i = x; i > 0; i--) fac *= i; } else fac = 1; return fac; } int main(void) { int 阅读全文
posted @ 2021-05-22 19:19 小鲨鱼2018 阅读(83) 评论(0) 推荐(0) 编辑
摘要:c语言中利用递归求非负整数的阶乘。 1、 #include <stdio.h> int factorial(int x) { if(x > 0) return x * factorial(x - 1); else return 1; } int main(void) { int a; puts("p 阅读全文
posted @ 2021-05-22 19:01 小鲨鱼2018 阅读(321) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> enum info { Gender, Season, Age, Invalid}; void gender(void) { puts("male.\n"); } void season(void) { puts("summer.\n"); } void 阅读全文
posted @ 2021-05-22 17:35 小鲨鱼2018 阅读(72) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> #define NUMBER 5 void bsort(int x[], int n) { int i, j; for(i = 0; i < n - 1; i++) { for(j = 1; j < n - i; j++) { if(x[j - 1] > 阅读全文
posted @ 2021-05-22 17:25 小鲨鱼2018 阅读(96) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> enum animal {Dog, Cat, Monkey, Invalid}; void dog(void) { puts("wang wang\n"); } void cat(void) { puts("miao miao\n"); } void mo 阅读全文
posted @ 2021-05-22 16:25 小鲨鱼2018 阅读(44) 评论(0) 推荐(0) 编辑
摘要:c语言中冒泡排序法。 1、升序排列 #include <stdio.h> #define NUMBER 5 void bsort(int x[], int n) { int i, j; for(i = 0; i < n - 1; i++) { for(j = n - 1; j > i; j--) { 阅读全文
posted @ 2021-05-22 10:47 小鲨鱼2018 阅读(727) 评论(0) 推荐(0) 编辑
摘要:c语言函数式宏、逗号表达式 一般由逗号运算符连接的两个表达式“a, b”在语法上可以视为一个表达式,在表达式后面添加分号,就构成了表达式语句。 #include <stdio.h> #define puts_alert(str) (putchar('\a'), puts(str)) int main 阅读全文
posted @ 2021-05-22 09:50 小鲨鱼2018 阅读(334) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> #define swap(type, a, b) {type tmp = a; a = b; b = tmp;} int main(void) { int x = 5, y = 10; printf("initial value x = %d\n", x) 阅读全文
posted @ 2021-05-21 23:16 小鲨鱼2018 阅读(98) 评论(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."); 阅读全文
posted @ 2021-05-21 22:45 小鲨鱼2018 阅读(76) 评论(0) 推荐(0) 编辑
摘要:定义一个函数式宏diff(x, y),返回x, y的差。 1、 #include <stdio.h> #define diff(x, y) ((x) - (y)) int main(void) { int a, b; puts("please input two integers."); print 阅读全文
posted @ 2021-05-21 22:24 小鲨鱼2018 阅读(228) 评论(0) 推荐(0) 编辑
摘要:c语言中使用函数式宏返回不同数据类型的值的平方。 1、 #include <stdio.h> #define sqr(x) ((x) * (x)) int main(void) { int a; puts("please input an integer."); printf("a = "); sc 阅读全文
posted @ 2021-05-21 22:11 小鲨鱼2018 阅读(270) 评论(0) 推荐(0) 编辑
摘要:c语言中使用十进制、二进制、八进制和十六进制输出0到65535的整数。 1、 #include <stdio.h> int count_bits(unsigned x) { int bits = 0; while(x) { if(x & 1U) bits++; x >>= 1; } return b 阅读全文
posted @ 2021-05-21 16:17 小鲨鱼2018 阅读(498) 评论(0) 推荐(0) 编辑
摘要:c语言中printf函数输出十进制、八进制和十六进制数。 1、 #include <stdio.h> int main(void) { unsigned a = 45; printf("101010 %u\n", a); printf("888888 %o\n", a); printf("16161 阅读全文
posted @ 2021-05-21 15:59 小鲨鱼2018 阅读(3099) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> unsigned set_n(unsigned x, int pos, int n) { int i; for(i = pos; i <= pos + n - 1; i++) { x = x | 1U << i; } return x; } unsigne 阅读全文
posted @ 2021-05-21 12:50 小鲨鱼2018 阅读(77) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> unsigned set(unsigned x, int pos) { return x | 1U << pos; } unsigned reset(unsigned x, int pos) { return x & (~(1U << pos)); } u 阅读全文
posted @ 2021-05-21 11:44 小鲨鱼2018 阅读(87) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> unsigned rrotate(unsigned x, int n) { return x >> n; } unsigned lrotate(unsigned x, int n) { return x << n; } int main(void) { u 阅读全文
posted @ 2021-05-21 11:12 小鲨鱼2018 阅读(67) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> #include <math.h> int main(void) { unsigned x, n; printf("test number: "); scanf("%u", &x); printf("move bits : "); scanf("%u", 阅读全文
posted @ 2021-05-21 10:29 小鲨鱼2018 阅读(78) 评论(0) 推荐(0) 编辑
摘要:c语言中输出十进制转换为二进制结果并指定显示的位数。 1、 #include <stdio.h> int count_bits(unsigned x) { int bits = 0; while(x) { if(x & 1U) bits++; x >>= 1; } return bits; } in 阅读全文
posted @ 2021-05-21 09:33 小鲨鱼2018 阅读(625) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> int count_bits(unsigned x) { int bits = 0; while(x) { if(x & 1U) bits++; x >>= 1; } return bits; } int int_bits(void) { return c 阅读全文
posted @ 2021-05-21 09:15 小鲨鱼2018 阅读(225) 评论(0) 推荐(0) 编辑
摘要:c语言中将一个十进制数按照二进制输出 1、 #include <stdio.h> int main(void) { int bits = 0; unsigned tmp = ~0U; while(tmp) { if(tmp & 1U) bits++; tmp >>= 1; } int i; unsi 阅读全文
posted @ 2021-05-21 08:22 小鲨鱼2018 阅读(612) 评论(0) 推荐(0) 编辑
摘要:c语言中输出不同数据类型在内存中的占位 1、 #include <stdio.h> int main(void) { int n = 0; unsigned x = ~0U; while(x) { if(x & 1U) n++; x >>= 1; } printf("the number of bi 阅读全文
posted @ 2021-05-20 23:05 小鲨鱼2018 阅读(303) 评论(0) 推荐(0) 编辑
摘要:c语言中输出十进制数转换为二进制数后包含1的数目 1、 #include <stdio.h> int main(void) { unsigned a; puts("please input a nonnegative integers."); printf("a = "); scanf("%u", 阅读全文
posted @ 2021-05-20 22:54 小鲨鱼2018 阅读(210) 评论(0) 推荐(0) 编辑
摘要:c语言中sizeof运算符,输出不同数据类型的长度 1、 a、sizeof运算符的符号是字节 b、各种数据类型的有符号型和无符号型长度一致 c、一般情况 short <= int <= long。 #include <stdio.h> int main(void) { puts("show the 阅读全文
posted @ 2021-05-20 21:18 小鲨鱼2018 阅读(656) 评论(0) 推荐(0) 编辑
摘要:c语言中的位以及不同的数据类型可以表示的数值的范围。 1、计算机中的所有数据类型都是用0和1的组合来表示的,这个0和1的占位就是位。 位是具有大量内存空间的运行环境的数据存储单元,可保存具有两种取值的对象。 不同数据类型在内存上的占位决定了其可以表示数值的范围。 比如无符号整型在内存上的占位为n,那 阅读全文
posted @ 2021-05-20 21:07 小鲨鱼2018 阅读(654) 评论(0) 推荐(0) 编辑
摘要:c语言中在编译器中判断char属于signed char 还是 unsigned char。 1、 判断CHAR_MIN非0,则输出“signed”, 如果为0,则输出“unsigned”,因为unsigned型的最小值为0. #include <stdio.h> #include <limits. 阅读全文
posted @ 2021-05-20 20:57 小鲨鱼2018 阅读(237) 评论(0) 推荐(0) 编辑
摘要:c语言中输出整型和字符型9中数据类型在编译器中可以表示的数值范围。 1、 a、无符号整型的显示使用 %u b、long型数据的显示使用 %l c、无符号整型的最小值为0. #include <stdio.h> #include <limits.h> int main(void) { printf(" 阅读全文
posted @ 2021-05-20 20:50 小鲨鱼2018 阅读(497) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> int main(void) { float x1, sum1 = 0.0; for(x1 = 0.0; x1 <= 1.0; x1 += 0.01) { sum1 += x1; } int i; float sum2 = 0.0; for(i = 1; 阅读全文
posted @ 2021-05-20 19:04 小鲨鱼2018 阅读(41) 评论(0) 推荐(0) 编辑
摘要:1、 利用浮点进行循环的时候,计算机不能保证计算机内部转换为二进制后不发生数据丢失,因此随着循环的进行,会发生误差的积累。 #include <stdio.h> int main(void) { int i; float x1 = - 0.01, x2; for(i = 0; i <= 100; i 阅读全文
posted @ 2021-05-20 18:37 小鲨鱼2018 阅读(72) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> #include <math.h> int main(void) { double x; puts("please input an double value."); printf("x = "); scanf("%lf", &x); printf("re 阅读全文
posted @ 2021-05-20 18:07 小鲨鱼2018 阅读(92) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> int main(void) { float x1, sum1 = 0.0; for(x1 = 0.0; x1 <= 1.0; x1 += 0.01) { sum1 += x1; } int i; float x2, sum2 = 0.0; for(i = 阅读全文
posted @ 2021-05-20 15:54 小鲨鱼2018 阅读(54) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> int main(void) { float x1 = -0.01; int x2 = 0; int i; float sum1 = 0.0 , sum2 = 0.0; for(i = 0; i <= 100; i++) { x1 += 0.01; sum 阅读全文
posted @ 2021-05-20 13:03 小鲨鱼2018 阅读(52) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> int main(void) { float x1 = -0.01; int x2 = 0; int i; for(i = 0; i <= 100; i++) { printf("x = %f x = %f\n", x1 += 0.01, x2++ / 1 阅读全文
posted @ 2021-05-20 12:55 小鲨鱼2018 阅读(43) 评论(0) 推荐(0) 编辑
摘要:创建一个程序,输入一个实数作为面积,求面积为该实数的正方形的边长。 #include <stdio.h> #include <math.h> int main(void) { double area; puts("please input the area."); printf("area = ") 阅读全文
posted @ 2021-05-20 11:25 小鲨鱼2018 阅读(63) 评论(0) 推荐(0) 编辑
摘要:1、创建一个程序,使用sizeof运算符显示3种浮点型的长度。 3种浮点型: float; double; long double; #include <stdio.h> int main(void) { printf("sizeof(float) = %d\n", sizeof(float)); 阅读全文
posted @ 2021-05-20 11:07 小鲨鱼2018 阅读(119) 评论(0) 推荐(0) 编辑
摘要:c语言中<math.h>头文件,计算两点之间的距离。 <math.h>头文件包含基本数学函数的函数原型声明。 1、 #include <stdio.h> #include <math.h> double dist(double x1, double y1, double x2, double y2) 阅读全文
posted @ 2021-05-20 10:39 小鲨鱼2018 阅读(796) 评论(0) 推荐(0) 编辑
摘要:c语言中整数的显示 以十进制、二进制、八进制、十六进制显示整数 1、 #include <stdio.h> int count_bits(unsigned x) { int bits = 0; while(x) { if(x & 1U) bits++; x >>= 1; } return bits; 阅读全文
posted @ 2021-05-19 22:50 小鲨鱼2018 阅读(480) 评论(0) 推荐(0) 编辑
摘要:编写inverse_n函数,返回将无符号整数x的第pos为开始的n位取反后的值。 1、 #include <stdio.h> unsigned inverse_n(unsigned x, int pos, int n) { int i; for(i = pos; i <= pos + n - 1; 阅读全文
posted @ 2021-05-19 19:06 小鲨鱼2018 阅读(79) 评论(0) 推荐(0) 编辑
摘要:编写reset_n函数,返回将无符号整数x的第pos为开始的n位设为0后的值。 1、 #include <stdio.h> unsigned reset_n(unsigned x, int pos, int n) { int i; for(i = pos; i <= pos + n - 1; i++ 阅读全文
posted @ 2021-05-19 18:44 小鲨鱼2018 阅读(64) 评论(0) 推荐(0) 编辑
摘要:编写set_n函数,返回将无符号整数x的第pos位到第pos + n - 1 位的 n 位 设为1后的值。 1、 #include <stdio.h> unsigned set_n(unsigned x, int pos, int n) { int i; for(i = pos; i <= pos 阅读全文
posted @ 2021-05-19 18:14 小鲨鱼2018 阅读(55) 评论(0) 推荐(0) 编辑
摘要:编写reverse函数,返回将无符号整数x的第pos位取反后的值。 1、 #include <stdio.h> unsigned reverse(unsigned x, int pos) { if(x >> pos & 1U) return (x & (~(1 << pos))); else ret 阅读全文
posted @ 2021-05-19 17:36 小鲨鱼2018 阅读(51) 评论(0) 推荐(0) 编辑
摘要:编写reset函数,返回无符号整数x的第pos为设为0后的值。 1、 #include <stdio.h> unsigned reset(unsigned x, int pos) { return (x & (~(1 << pos))); } int main(void) { unsigned x; 阅读全文
posted @ 2021-05-19 16:39 小鲨鱼2018 阅读(45) 评论(0) 推荐(0) 编辑
摘要:编写函数,返回将无符号整数的第pos位设置为1后的值。 1、 #include <stdio.h> unsigned set(unsigned x, int pos) { return (x | 1 << pos); } int main(void) { unsigned x; int n; put 阅读全文
posted @ 2021-05-19 13:02 小鲨鱼2018 阅读(60) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> unsigned rrotate(unsigned x, int n) { printf("rrotate = %u\n", x >> n); } unsigned lrotate(unsigned x, int n) { printf("lrotate 阅读全文
posted @ 2021-05-18 21:30 小鲨鱼2018 阅读(45) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> #include <math.h> int main(void) { unsigned x; int n; puts("please input an unsigned number and an integer."); printf("x = "); s 阅读全文
posted @ 2021-05-18 19:56 小鲨鱼2018 阅读(70) 评论(0) 推荐(0) 编辑
摘要:c语言中按位逻辑运算符、位移运算符 #include <stdio.h> int count_bits(unsigned x) { int bits = 0; while(x) { if(x & 1U) bits++; x >>= 1; } return bits; } int int_bits(v 阅读全文
posted @ 2021-05-18 12:37 小鲨鱼2018 阅读(136) 评论(0) 推荐(0) 编辑
摘要:c语言中按位逻辑运算符、位移运算符 #include <stdio.h> int count_bits(unsigned x) { int bits = 0; while(x) { if(x & 1U) bits++; x >>= 1; } return bits; } int int_bits(v 阅读全文
posted @ 2021-05-18 12:35 小鲨鱼2018 阅读(126) 评论(0) 推荐(0) 编辑
摘要:#include <stdio.h> int count_bits(unsigned x) { int bits = 0; while(x) { if(x & 1U) bits++; x >>= 1; } return bits; } int int_bits(void) { return coun 阅读全文
posted @ 2021-05-17 21:21 小鲨鱼2018 阅读(257) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> int main(void) { int n; printf("sizeof(1) = %u\n", (unsigned)sizeof(1)); printf("sizeof(+1) = %u\n", (unsigned)sizeof(+1)); prin 阅读全文
posted @ 2021-05-16 21:11 小鲨鱼2018 阅读(135) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> void fun(void) { static int times = 0; times++; printf("put_count: %d\n", times); } int main(void) { int n; puts("please input a 阅读全文
posted @ 2021-05-11 12:27 小鲨鱼2018 阅读(53) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> #define NUMBER 5 int main(void) { static double array[NUMBER]; int i; for(i = 0; i < NUMBER; i++) { printf("array[%d] = %.1f\n", 阅读全文
posted @ 2021-05-11 12:13 小鲨鱼2018 阅读(41) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> void sumup(int x[2][4][3], int y[4][3]) { int i, j, k; for(i = 0; i < 4; i++) { for(j = 0; j < 3; j++) { for(k = 0; k < 2; k++) 阅读全文
posted @ 2021-05-11 11:59 小鲨鱼2018 阅读(48) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> void multiply(int x[4][3], int y[3][4], int z[4][4]) { int i, j, k; for(i = 0; i < 4; i++) { for(j = 0; j < 4; j++) { for(k = 0; 阅读全文
posted @ 2021-05-11 11:32 小鲨鱼2018 阅读(49) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> #define NUMBER 7 int search(const int x[], int y[], int key, int n) { int i, times = 0; for(i = 0; i < n; i++) { if(x[i] == key) 阅读全文
posted @ 2021-05-11 11:13 小鲨鱼2018 阅读(55) 评论(0) 推荐(0) 编辑
摘要:python中global关键字实现在函数内部对全局变量进行修改。 1、测试 >>> v = 10 >>> def test(): v = 5 print(v) >>> test() 5 >>> v ## 这说明在函数内部修改的全局变量只能在函数内部生效,不会真正影响全局变量 10 加global关 阅读全文
posted @ 2021-05-09 23:00 小鲨鱼2018 阅读(1209) 评论(0) 推荐(0) 编辑
摘要:R语言中sapply函数。 1、 x=c(1:5) x sapply(x,function(x) {x^2}) 阅读全文
posted @ 2021-05-07 22:53 小鲨鱼2018 阅读(1150) 评论(0) 推荐(0) 编辑
摘要:linux系统awk命令统计每一个用户进程占用的内存。 1、 [root@centos7 test2]# ps aux | awk 'NR != 1 {a[$1]+=$6} END{for(i in a) print i, a[i]}' geoclue 3096 rpc 104 rstudio+ 5 阅读全文
posted @ 2021-05-07 19:16 小鲨鱼2018 阅读(442) 评论(0) 推荐(0) 编辑
摘要:linux系统awk命令拆分文件。 1、 [root@centos7 test2]# ls file.txt [root@centos7 test2]# cat file.txt -rw-r--r-- 1 root 52457 Aug 10 2019 ngx_http.c -rw-r--r-- 1 阅读全文
posted @ 2021-05-07 18:58 小鲨鱼2018 阅读(609) 评论(0) 推荐(0) 编辑
摘要:c语言 6-5 #include <stdio.h> int sumup(int n) { int sum = 0; int i; for(i = 1; i <= n; i++) { sum += i; } return sum; } int main(void) { int i; puts("pl 阅读全文
posted @ 2021-05-07 10:14 小鲨鱼2018 阅读(76) 评论(0) 推荐(0) 编辑
摘要:c语言6-4 #include <stdio.h> int sqr(int a) { return a * a; } int pow4(int a) { return sqr(sqr(a)); } int main(void) { int i; puts("please input an integ 阅读全文
posted @ 2021-05-07 10:08 小鲨鱼2018 阅读(64) 评论(0) 推荐(0) 编辑
摘要:c语言 6-3 #include <stdio.h> int cube(int a) { return a * a * a; } int main(void) { int i; puts("please input an integer."); printf("i = "); scanf("%d", 阅读全文
posted @ 2021-05-07 10:03 小鲨鱼2018 阅读(74) 评论(0) 推荐(0) 编辑
摘要:输出三个数中的最小值。 #include <stdio.h> int min3(int a, int b, int c) { int min = a; if(b < min) min = b; if(c < min) min = c; return min; } int main(void) { i 阅读全文
posted @ 2021-05-07 10:00 小鲨鱼2018 阅读(1801) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> int min2(int a, int b) { int min = a; if(b < min) min = b; return min; } int main(void) { int x, y; puts("please input two integ 阅读全文
posted @ 2021-05-06 23:20 小鲨鱼2018 阅读(69) 评论(0) 推荐(0) 编辑
摘要:第一个java程序。 package hello; public class Hello { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Hello W 阅读全文
posted @ 2021-05-06 21:56 小鲨鱼2018 阅读(30) 评论(0) 推荐(0) 编辑
摘要:c语言中自定义函数计算x的n次方。 1、直接输出形式 #include <stdio.h> int main(void) { int i, x, n; int tmp = 1; puts("please input the values of x and n."); printf("x = "); 阅读全文
posted @ 2021-05-06 19:04 小鲨鱼2018 阅读(4571) 评论(0) 推荐(0) 编辑
摘要:c语言中while语句控制程序循环的次数 1、 #include <stdio.h> int main(void) { int i; puts("please input an integer."); printf("i = "); scanf("%d", &i); while(i-- > 0) { 阅读全文
posted @ 2021-05-06 18:33 小鲨鱼2018 阅读(663) 评论(0) 推荐(0) 编辑
摘要:函数定义: 函数调用: 函数定义:函数头和函数体。 函数头:包括返回值类型、函数名和形参声明 函数体:复合语句,仅在摸个函数中使用的变量,原则上应在该函数中声明和使用,但要注意不能声明和形参同名的变量,否则会发生变量名冲突的错误。 #include <stdio.h> int max2(int a, 阅读全文
posted @ 2021-05-04 10:52 小鲨鱼2018 阅读(1961) 评论(0) 推荐(0) 编辑
摘要:python中创建字典、字典的访问 1、 >>> test1 = {"aaa":111,"bbb":222,"ccc":333} >>> test1 {'aaa': 111, 'bbb': 222, 'ccc': 333} >>> type(test1) <class 'dict'> >>> 2、 阅读全文
posted @ 2021-05-03 20:26 小鲨鱼2018 阅读(175) 评论(0) 推荐(0) 编辑
摘要:1、 问题 >>> test2 = dict((('F',20),('i',40),('s',80))) Traceback (most recent call last): File "<pyshell#171>", line 1, in <module> test2 = dict((('F',2 阅读全文
posted @ 2021-05-03 19:17 小鲨鱼2018 阅读(838) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> #define NUMBER 1000 int main(void) { int i, j, num, a[NUMBER], max, b[11] = {0}; do { printf("num = "); scanf("%d", &num); if(nu 阅读全文
posted @ 2021-05-03 17:25 小鲨鱼2018 阅读(56) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> int main(void) { int i, j, k, a[2][4][3], b[4][3] = {0}; puts("please input the elements of the array."); for(i = 0; i < 2; i++) 阅读全文
posted @ 2021-05-03 15:15 小鲨鱼2018 阅读(35) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> int main(void) { int i, j, a[6][2], b[2] = {0}, c[6] = {0}; puts("please input the elements of array a."); for(i = 0; i < 6; i++ 阅读全文
posted @ 2021-05-03 12:46 小鲨鱼2018 阅读(38) 评论(0) 推荐(0) 编辑
摘要:c语言中实现矩阵的转置 1、 #include <stdio.h> int main(void) { int i, j, a[4][6], b[6][4]; puts("please input the elements of matrix a."); for(i = 0; i < 4; i++) 阅读全文
posted @ 2021-05-03 12:07 小鲨鱼2018 阅读(1885) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> int main(void) { int i, j, a[6][2]; puts("please input the elements of the array."); for(i = 0; i < 6; i++) { for(j = 0; j < 2; 阅读全文
posted @ 2021-05-03 11:35 小鲨鱼2018 阅读(51) 评论(0) 推荐(0) 编辑
摘要:c语言中计算矩阵的乘积。 矩阵相乘的条件:左侧矩阵的列数等于右侧矩阵的行数。 矩阵相乘的结果:行数为左侧矩阵的行数,列数为右侧矩阵的列数。 #include <stdio.h> int main(void) { int i, j, k, a[4][6], b[6][7], c[4][7] = {0} 阅读全文
posted @ 2021-05-03 10:21 小鲨鱼2018 阅读(1208) 评论(0) 推荐(0) 编辑
摘要:python中字符串拼接的三种方法。 1、加号拼接 >>> a = "abcd" >>> b = "xyzm" >>> a 'abcd' >>> b 'xyzm' >>> a + b 'abcdxyzm' 2、join拼接 >>> c = ["abcd","xyzm"] >>> c ['abcd', 阅读全文
posted @ 2021-05-01 23:16 小鲨鱼2018 阅读(638) 评论(0) 推荐(0) 编辑
摘要:python中字符串的格式化。 1、format 位置参数 >>> "{0} and {1}".format("aaa","bbb") 'aaa and bbb' >>> "{0},{1} and {2}".format("aaa","bbb","ccc") 'aaa,bbb and ccc' 关键 阅读全文
posted @ 2021-05-01 23:11 小鲨鱼2018 阅读(153) 评论(0) 推荐(0) 编辑
摘要:python中字符串的拼接。 1、 >>> test1 = ["aaa","bbb","ccc","ddd","eee"] >>> test1 ['aaa', 'bbb', 'ccc', 'ddd', 'eee'] >>> "-".join(test1) 'aaa-bbb-ccc-ddd-eee' 阅读全文
posted @ 2021-05-01 22:56 小鲨鱼2018 阅读(66) 评论(0) 推荐(0) 编辑
摘要:1、问题 [root@centos7 Python-3.9.4]# ln -s python /usr/bin/python [root@centos7 Python-3.9.4]# python -bash: /usr/bin/python: Too many levels of symbolic 阅读全文
posted @ 2021-05-01 22:52 小鲨鱼2018 阅读(3226) 评论(0) 推荐(0) 编辑
摘要:python中拆分字符串 1、 >>> test1 = "abxcdxefxfh" >>> test1 'abxcdxefxfh' >>> test1.split(sep = "x") ['ab', 'cd', 'ef', 'fh'] 阅读全文
posted @ 2021-05-01 21:51 小鲨鱼2018 阅读(384) 评论(0) 推荐(0) 编辑
摘要:python中替换字符串中特定字符。 1、 >>> test1 = "abdadcadadfa" >>> test1 'abdadcadadfa' >>> test1.replace("a","x") 'xbdxdcxdxdfx' >>> test1.replace("a","x",2) ## 指定 阅读全文
posted @ 2021-05-01 21:48 小鲨鱼2018 阅读(2683) 评论(0) 推荐(0) 编辑
摘要:1、返回第一个出现的索引 >>> test1 'absacaxy' >>> test1.find("a") 0 2、返回特定字符的所有索引 >>> test1 'absacaxy' >>> b = test1.count("a") >>> c = -1 >>> for i in range(b): 阅读全文
posted @ 2021-05-01 21:34 小鲨鱼2018 阅读(3782) 评论(0) 推荐(0) 编辑
摘要:python中查找字符串中字符出现的次数 1、 >>> test1 = "absacaxy" >>> test1.count("a") 3 >>> test1.count("a",0,4) ## 设置查找范围 2 2、统计所有字符出现的次数 >>> test1 = "abdeaceb" >>> a 阅读全文
posted @ 2021-05-01 21:27 小鲨鱼2018 阅读(2063) 评论(0) 推荐(0) 编辑
摘要:1、 删除左边空白 >>> test1 = " abcd " >>> test1 ' abcd ' >>> test1.lstrip() 'abcd ' 2、删除右边空白 >>> test1 ' abcd ' >>> test1.rstrip() ' abcd' 3、删除两边空白 >>> test1 阅读全文
posted @ 2021-05-01 21:20 小鲨鱼2018 阅读(693) 评论(0) 推荐(0) 编辑
摘要:1、大写改为小写 >>> test1 = "abCDEfg" >>> test1 'abCDEfg' >>> test1.upper() 'ABCDEFG' 2、小写变大写 >>> test1 'abCDEfg' >>> test1.lower() 'abcdefg' >>> test1 'abCD 阅读全文
posted @ 2021-05-01 21:14 小鲨鱼2018 阅读(683) 评论(0) 推荐(0) 编辑
摘要:python中zip函数 1、python中zip函数用于返回由可迭代参数共同组成的元组。 长度不一致时,以短的序列进行迭代。 >>> test1 = ["aaa","bbb","ccc","ddd"] >>> test2 = (111,222,333,444,555) >>> test3 = "a 阅读全文
posted @ 2021-05-01 20:44 小鲨鱼2018 阅读(605) 评论(0) 推荐(0) 编辑
摘要:python中enumerate函数。 1、python中enumerate函数 enumerate函数的应用对象为序列(列表、元组、字符串), 返回一个由二元组组成的可迭代对象,二元组由可迭代参数的索引号及其对应的元素组成。 列表 >>> test1 = ["aaa","bbb","ccc"] > 阅读全文
posted @ 2021-05-01 20:37 小鲨鱼2018 阅读(590) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> int main(void) { int i, j, k, a[2][4][3], b[4][3] = {}; for(i = 0; i < 2; i++) { for(j = 0; j < 4; j++) { for(k = 0; k < 3; k++) 阅读全文
posted @ 2021-05-01 18:26 小鲨鱼2018 阅读(52) 评论(0) 推荐(0) 编辑
摘要:1、 #include <stdio.h> int main(void) { int i, j, a[8][3] = {}; puts("please input the scores of the students."); for(i = 0; i < 6; i++) { for(j = 0; j 阅读全文
posted @ 2021-05-01 17:30 小鲨鱼2018 阅读(50) 评论(0) 推荐(0) 编辑
摘要:求3行4列矩阵和4行5列矩阵的乘积。 1、 #include <stdio.h> int main(void) { int i, j, k, a[3][4], b[4][5], c[3][5] = {0}; puts("please input the elements of matrix a.") 阅读全文
posted @ 2021-05-01 12:42 小鲨鱼2018 阅读(286) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示