- 博客(31)
- 资源 (1)
- 收藏
- 关注
原创 html 缩放位移小案例
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title&...
2022-03-05 16:58:03
100
原创 //求一个数二进制中1的个数
#include <stdio.h>int main(){//求一个数二进制中1的个数int a = 10;int count = 0;while (a){if(a%2==1)count++;a >>=1;}printf("%d\n", count);return 0;}
2021-10-10 22:23:31
70
原创 模拟memmove:
void *my_memmove(void *dest, void *src, size_t num){void *ret = dest;if (dest - src > 0){char *enddest = (char *)dest + num - 1;char *endsrc = (char *)src + num - 1;while (num--){*enddest = *endsrc;endsrc--;enddest--;}}else
2021-09-25 23:43:01
87
原创 strtok:使用方法
#include <stdio.h>#include <string.h>int main(){char arr[] = "qianshandaipipi@163.com";char buf[1024];strcpy(buf, arr);char *sep = "@.";char *ret =NULL;for(ret = strtok(buf,sep);ret!=NULL;ret = strtok(NULL,sep))printf("%s\
2021-09-25 00:57:37
60
原创 strstr:模拟实现
#include <stdio.h>#include <assert.h>char *my_strstr(const char *dest, const char *src){assert(dest != NULL && src != NULL);if (*src == '\0')return (char *)src;const char *p1 = dest;const char *p2 = src;const char
2021-09-24 23:58:41
64
原创 字符串左旋(右旋同理)
#include <stdio.h>#include<string.h>void change_test(char * arr,int k){char temp = 0;int sz = strlen(arr);for(int j = 0;j<k;j++){for (int i = 0; i < sz-1; i++){temp = arr[i];arr[i] = arr[i + 1];arr[i + 1] = tem
2021-09-21 23:04:22
45
原创 求一个数的平方根(向下取整)
#include <stdio.h>int test(int n){if (n <= 1)return n;int begin = 1;int end = n / 2;int middle;while (begin <= end){middle = (begin + end) / 2;if (middle == n / middle)return middle;else{if (middle <
2021-09-19 12:56:29
733
原创 寻找凶手:
#include <stdio.h>int main(){//猜凶手// 日本某地发生一起谋杀案,警察通过排查发现4名嫌疑人// A说:不是我// B说:是C// C说:是D// D说:C在胡说// 已知:有3个人说了真话,一个说了假话,问凶手是谁//假设说的真话的为1假话的为0int killer = 0;for (killer = 'a'; killer <= 'd'; killer++){if ((killer !=
2021-09-18 12:44:39
73
原创 杨辉三角:
#include <stdio.h>int main(){//案例:杨辉三角// 1// 1 1// 1 2 1// 1 3 3 1// 1 4 6 4 1int arr[10][10] = {0};int i;int j;for (i = 0; i < 10; i++){for (j = 0; j <= i; j++){if (j == 0){arr[i][j] = 1;}if(j==i)
2021-09-18 11:10:22
67
原创 打印菱形:
#include <stdio.h>void print(int x){ int n = x / 2+1; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= 2 * n - 1; ++j) { if (j <= n - i || j >= n + i) { printf(" ".
2021-09-17 13:11:41
85
原创 水仙花数:
#include <stdio.h>int times_num(const int x){ int num = x; int count = 1; while (num > 9) { count += 1; num /= 10; } return count;}int Daffodil(){ int x = 0; printf("请输入一个数\n"); scanf("%.
2021-09-17 11:01:41
93
原创 算法题:Sn=a+aa+aaa+aaaa+aaaaa ......(其中a 和n 为整数)
#include <stdio.h>int multiply(int x){ if (x >= 1) { return 10 * multiply(x - 1); } return 1;}int test(int num, int n){ int init = num; int coefficient = num; int count = 0; for (int i = 0; i <..
2021-09-17 10:43:52
330
原创 字符串逆序:
#include <stdio.h>#include <string.h>void reverse(char *str){ int len = strlen(str); char *left = str; char *right = str + len - 1; while (left < right) { char temp = 0; temp = *left; *left =.
2021-09-16 12:23:17
100
原创 多级指针:
#include <stdio.h>int main(){ char *c[] = {"ENTER","NEW","POINT","FIRST"}; char **pc[] = {c+3,c+2,c+1,c}; char ***ppc = pc;printf("%s\n",**++ppc);//POINTprintf("%s\n",*--*++ppc+3);//ERprintf("%s\n",*ppc[-2]+3);//STprintf("%s.
2021-09-14 00:01:19
60
原创 qsort原理初阶解析:
#include <stdio.h>void Swap(char *buf1, char *buf2, int width){ for (int i = 0; i < width; ++i) { char temp ; temp = *buf1; *buf1 = *buf2; *buf2 = temp; buf1++; buf2++; }}void bubb.
2021-09-09 00:48:26
62
原创 qsort使用:
#include <stdio.h>#include <stdlib.h>#include <string.h>struct Stu{ char name[20]; int age;};int cmp_struct(const void * e1,const void * e2){// return(*(struct Stu *)e1).age-(*(struct Stu *)e2).age; return strcmp.
2021-09-08 23:45:00
47
原创 回调函数:
#include <stdio.h>void test(void (*ps)( char *)){ printf("hello\n"); ps("你好吗");}void print( char * str){ printf("%s\n",str);}int main(){ test(print); return 0;}
2021-09-08 00:12:23
35
原创 函数指针数组:初阶
#include <stdio.h>void menu(){ printf("*** 1.Add 2.Sub 3.Mul 4.Div 0.exit ***\n");}int Add(int x, int y){ return x + y;}int Sub(int x, int y){ return x - y;}int Mul(int x, int y){ return x * y;}int Div(int .
2021-09-07 23:21:13
70
原创 函数指针数组:
#include <stdio.h>int Add(int x, int y){ return x + y;}int Sub(int x, int y){ return x - y;}int Mul(int x, int y){ return x * y;}int Div(int x, int y){ return x / y;}int main(){ int (*p[4])(int, int) = {Add, Su.
2021-09-07 01:16:51
79
原创 函数指针:
#include <stdio.h>int Add(const int a, const int b){ return a + b;}void Print(char *str){ printf("%s\n", str);}int main(){ int a = 10; int b = 20; int res = Add(a, b); printf("%d\n", res); //函数指针 int (*pa)(.
2021-09-07 00:12:29
37
原创 浮点数存储规则
1:> float (-1)*S*M*2^E二进制表示数:案例 5.5 ->101.1S=0;E=2;M=1.011 个位数1默认舍弃S E+127 M ->01000000101100000000000000000000 二进制数的存储方式S E+127 M 1bit 8bit 23bit...
2021-09-03 00:49:55
45
原创 字节序排列方式
#include <stdio.h>//字节序排列方式int main(){ int a = 1; char *pa = &a; if (*pa == 1) { printf("小端字节序"); }else { printf("大端字节序"); } return 0;}
2021-09-02 01:00:55
127
原创 字符串的复制:
#include <stdio.h>#include "test.h"int main() { char name1[] = "**********************"; char name2[] = "hello"; my_strcpy(name1, name2); printf("%s\n", name1); return 0;}void my_strcpy(char *name1, char *name2) {// w.
2021-09-01 00:42:46
46
原创 struct定义
typedef struct s1{char name[20];int age;}S1 ;struct s2{char name[20];int age;};
2021-08-31 01:04:33
84
原创 求两个整型二进制数字中不同位数的和
#include <stdio.h>int count_diff_bit(int m, int n) { int temp = m ^n; int count = 0; while (temp) { temp = temp & (temp - 1); count++; } return count;}int main() { int m, n; m = n = 0;printf("亲.
2021-08-29 23:57:49
164
原创 求二进制中1的个数
int count_bit_one(int n) { //int count_bit_one(unsigned int n){ int count = 0; /* while (n) { if (n % 2) { count++; } n = n / 2; }*/ int range = 8*sizeof (n); for (int i = 0; i < ra.
2021-08-29 22:14:21
38
原创 冒泡排序:
#include <stdio.h>void bubble_sort(int arr[], int sz){for (int i = 0; i < sz - 1; i++){for (int j = 0; j < sz - 1 - i; j++){int temp = 0;if (arr[j] > arr[j + 1]){temp = arr[j];arr[j] = arr[j + 1];arr[j + 1] = te
2021-08-23 23:36:34
46
原创 递归案例:青蛙跳台阶
#include <stdio.h>int method_nums(int n){if (n >= 0 && n <= 1)return 1;elsereturn method_nums(n - 1) + method_nums(n - 2);}int main(){//案例青蛙跳台阶<需要跳到n阶>一次只能跳一格或者两格:问有多少种跳法?int n = 0;printf("请输入要跳到的台阶数"
2021-08-22 22:52:05
61
原创 递归案例:求字符串的长度
#include<stdio.h>int str_len(char * name){if(*name != '\0'){return 1+ str_len(name+1);}else{return 0;}}int main(){char name[] = "pipi";int res = str_len(name);printf("%d \n",res);}
2021-08-22 22:27:10
69
原创 递归案例:数字输出
#include <stdio.h>#include <stdlib.h>void print(int num){if (num > 9){print(num / 10);}printf("%d ", num%10);}int main(){//example ://输入1234 输出 1 2 3 4unsigned int num = 0;printf("请输入一个数字");scanf("%d", &
2021-08-22 22:25:21
116
原创 斐波那契算法:
#include <stdio.h>/* int fibonacci(int n){if (n <= 2 && n >= 1)return 1;elsereturn fibonacci(n - 1) + fibonacci(n - 2);}*/int fibonacci(int n){int a = 1;int b = 1;int c = 1;/* int c = 0;if (..
2021-08-22 22:21:51
93
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人