自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(14)
  • 收藏
  • 关注

原创 python循环打印乘法表

i=1while i<=9: j=1 while j<=i: print(f'{j}*{i}={j*i} ',end='') j+=1 print() i+=11*1=1 1*2=2 2*2=4 1*3=3 2*3=6 3*3=9 1*4=4 2*4=8 3*4=12 4*4=16 1*5=5 2*5=10 3*5=15 4*5=20 5*5=25 1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6.

2022-04-01 10:50:41 1490

原创 C.code模拟实现memcpy函数

代码一开始保存被更改的数组地址,因为后面指针会移动,新定义一个指针用来指向首元素地址 不知道指针str1和str2的步长,不妨强制转换成cha*指针,让两个指针每次只走一个字节 numb存放的是需要拷贝过去的数据字节长度#define _CRT_SECURE_NO_WARNINGS 1#include <stdio.h>//模拟实现内存拷贝函数void* myMemcpy(void* str1, void const* str2, size_t numb) { void* r

2022-03-13 16:05:49 279

原创 C.code模拟实现strcmp函数

strcmp比较两个字符串str1和str2#define _CRT_SECURE_NO_WARNINGS 1//模拟实现strcmp函数#include <stdio.h>int myStrcmp(const char* str1,const char* str2) { while (*str1 == *str2) { if (*str1==0) { return 0; } str1++; str2++; } return *str1 - *str2;

2022-03-13 11:23:14 131

原创 C.code自拟实现strcat函数

代码 先用空指针接收str1的地址,里面存放的就是str1的首元素地址 对str1进行解引用,直到*str1指针访问到"\0",跳出循环,此时我们的指针指向的是"\0" *str1++ = *str2++,先将str2第一个元素的地址赋值给刚刚str1指针指向的位置(即"\0"的位置),然后两个指针向后移一位,如此循环,直到strl2把自己的"\0"赋值给str1,循环结束 此时返回ret指针指向的str1首元素的地址即可#include...

2022-03-12 23:22:15 124

原创 C.code比较两字符串是否是左旋转得到

玩法字符串A=“ABCD”(flag)字符串B=“BCDA”字符串C=“ABDC”B可以由A左旋得到,C不可由A左旋得到思路不妨将A与A拼接在一起,形成一个长字符串AA:ABCDABCD,再将B从左边开始与AA进行比较(即查看B是否尾AA的子串)1. ABCDABCD BCDA2.ABCDABCD BCDAB是AA子串3.ABCDABCD ABDC4.ABCDABCD ABDC5.ABCDABCD ...

2022-03-12 20:39:37 57

原创 C.code 左旋数组

类似于队的玩法,输入一个数字k,数组前k个元素从数组的左边出队,后面的元素依次往前站队,出队的k个元素,从队尾依次站回来。思路char arr[ ]="ABCDEFG";需要旋转前3个元素"ABCDEFG"先将前三个元素逆序一下得到CBADEFG 将后面剩余元素也逆序得到CBAGFED 将CBAGFED整个再进行逆序得到DEFGABC相关代码#define _CRT_SECURE_NO_WARNINGS 1#include<stdio.h>#i...

2022-03-12 19:10:37 275

原创 C.code简易计算器

1.利用函数指针数组模拟实现简易计算器程序主体部分:将函数放于一个函数指针数组中,通过访问下标来访问函数#define _CRT_SECURE_NO_WARNINGS 1#include <stdio.h>#include "test.h"#include<windows.h>int main() { int input = 0; double a=0,b=0,ret=0; double(*p[5])(double x, double y) = {NUL

2022-03-10 20:52:36 261

原创 C.code打印菱形

1.分开打印上下部分找出空格和*之间的规律即可#define _CRT_SECURE_NO_WARNINGS 1#define lenth 7#include <stdio.h>int main() { int i = 0; int j = 0; for (i = 0; i < (lenth+1)/2; i++) { for (j = 0; j < (lenth - 1) / 2 - i; j++) { printf(" "); } for (

2022-03-09 21:21:34 151

原创 C.code字符串逆序打印

第一种将字符串保存在指针里,算出字符串的长度,指针+字符串长度-1,再解引用就可以访问字符串(除开最后“\0”的字符)最后一个元素,再用循环,依次逆序打印#define _CRT_SECURE_NO_WARNINGS 1#include <stdio.h>#include <string.h>//字符串逆序int main() { char a[] = { "abcdefgh" }; int flag = strlen(a),i=0; char* p = a;

2022-03-09 20:14:56 387

原创 C.code用指针打印数组元素

第一版传首元素地址给指针,再计算数组的元素个数,用指针循环打印数组的元素#define _CRT_SECURE_NO_WARNINGS 1#include <stdio.h>void print(int *p,int b) { int i = 0; for (i = 0; i < b; i++) { printf("%d ", *(p + i)); } printf("\n");}int main() { int a[] = { 1,2,3,4,5,6 };

2022-03-09 19:17:42 126

原创 C.code 计算整形数据二进制中包含多少个“1”

第一版#include <stdio.h>int numbs(int a) { int count = 0; for (int i = 0; i < sizeof(a) * 8; i++) { if (a & 1 << i) { count++; } } return count;}第二版int numbs(int a) { int count = 0; while (a) { a =a&(a - 1); c

2022-03-06 22:39:32 143

原创 C.code自拟strlen

#include <assert.h>size_t My_strlen(char const* p){ size_t count = 0; assert(p);//p为空指针的时候自然会返回0 for (; *p != '\0'; count++, p++) { } return count;}vs2022代码size_t His_strlen(char const* p) { const char* q = p; while (*p++);//p指向空指针返回值0.

2022-03-06 21:23:39 197

原创 Code求n的阶乘(递归函数)

#define _CRT_SECURE_NO_WARNINGS 1#include <stdio.h>int test(int X) { if (X <= 0) { return 1; } else { return (X*(test(X - 1))); }}int main(){ int a = 0; scanf("%d", &a); printf("%d\n", test(a)); return 0;}

2022-03-02 16:36:22 102

原创 code2数字游戏

要求:随机生成1-100之间的数字,猜数字大小并给出提示#define _CRT_SECURE_NO_WARNINGS 1#include <stdio.h>#include <string.h>#include <Windows.h>#include <stdlib.h>#include <time.h>void mune() { printf("********************\n"); printf("*****

2022-03-01 16:07:36 132

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除