C
bengbengxiong66
这个作者很懒,什么都没留下…
展开
-
将整数的二进制反向输出
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> void Binary(int n) { int i = 0; int arr[32] = { 0 }; for (; i < 32; i++) { int ret = 0; ret = n % 2; arr[i] = ret...原创 2018-10-24 22:01:32 · 883 阅读 · 0 评论 -
模拟实现strcat
#include <stdio.h> #include <stdlib.h> #include <assert.h> int Mystrcat(char * dest, const char * source) { assert(dest != NULL); assert(source != NULL); while (dest != ‘\0’) { ++des...原创 2018-11-08 21:54:18 · 85 阅读 · 0 评论 -
模拟实现strcpy
#include <stdio.h> #include <stdlib.h> #include <assert.h> int Mystrcpy(char* dest, const char* source) { assert(dest != NULL); //如果断言中表达式的...原创 2018-11-08 21:49:36 · 91 阅读 · 0 评论 -
模拟实现strlen
#include <stdio.h> #include <stdlib.h> 第一种方法: int Mystrlen(const char* str ) { if (str == NULL) { return -1; } if (*str == ‘\0’) { return 0; } int size = 0; while (str != ‘\0’) { ++size; +...原创 2018-11-08 21:42:03 · 93 阅读 · 0 评论 -
判断一个字符串是否为另外一个字符串旋转之后的字符串
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <string.h> int Is_Revolve(char arr[], char arr1[]) { char *ret = 0; int len1 = strlen(arr); int len2 =...原创 2018-11-01 22:26:18 · 131 阅读 · 0 评论 -
实现一个函数,可以左旋字符串中的k个字符
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <string.h> int Left_hand(char arr[], int n) { int len = strlen(arr)-1; char* str = arr; for (int i = ...原创 2018-11-01 22:11:51 · 94 阅读 · 0 评论 -
调整数组使奇数全部都位于偶数前面
#include <stdio.h> #include <stdlib.h> int sort(int arr[], int size) { int* left = arr; //定义一个左指针指向数组第一个元素 int* right = arr+size-1; ...原创 2018-10-30 19:36:57 · 107 阅读 · 0 评论 -
找出一组数据中只出现一次的数
#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; void once(int arr[9],int size) { int ret; for (int i = 0; i &lt; size; ++i) { ret = 0 ^ arr[i]; } printf("%d\n", ret); } int main() {原创 2018-10-24 22:08:49 · 237 阅读 · 0 评论 -
不使用(a+b)/2这种方式,求两个数的平均值
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> int main() { int n; int m; printf(“请输入两个整数:”); scanf("%d %d", &n, &m); int ret = (n + m) >> 1; ...原创 2018-10-24 22:05:52 · 98 阅读 · 0 评论 -
打印杨辉三角形
#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #define M 9 #define N 9 void main() { int a[M][N], i, j; for (i = 0; i &lt; M; i++) { a[i][0] = 1; a[i][i] = 1; } for (i = 2; i &lt; M; i++) {原创 2018-10-23 23:38:05 · 92 阅读 · 0 评论 -
实现strcmp
#include <stdio.h> #include <stdlib.h> #include <assert.h> int Mystrcmp(const char * str1, const char * str2) { assert(str1 != NULL); assert(str2 != NULL); while (*str1 != ‘\0’&&...原创 2018-11-08 22:18:27 · 127 阅读 · 0 评论