自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 练习使用qsort函数排序各种类型的数据。

#include<stdio.h>#include<string.h>#pragma warning(disable:4996)int cmp(const void *x, const void *y) //整形 return (*(int*)x) - (*(int*)y);}int cmp1(const void *x, const void *y) ...

2018-05-30 21:24:53 446

原创 模仿qsort的功能实现一个通用的冒泡排序。

#include<stdio.h>#include<string.h>#pragma warning(disable:4996)int cmp(const void *x, const void *y){ return (*(char*)x) - (*(char*)y);}void swap(char *buf1, char *buf2, int width)...

2018-05-30 21:20:01 192

原创 指针

在了解之前 我们要先知道什么是指针,给大家截取一段百度百科:在计算机科学中,指针(Pointer)是编程语言中的一个对象,利用地址,它的值直接指向(points to)存在电脑存储器中另一个地方的值。由于通过地址能找到所需的变量单元,可以说,地址指向该变量单元。因此,将地址形象化的称为“指针”。我们可以这样理解:其实,指针变量就是一个变量,用来存放地址的变量。(存放在指针中的值都能被当做地址处理)...

2018-05-30 19:59:54 330

原创 模拟实现strcmp

#include<stdio.h>#include<assert.h>char *my_strcmp(const char *src, const char *dst){ assert(src); assert(dst); while ((*src) == (*dst)) { if (*src == '\0') return 0; src++;...

2018-05-23 17:29:25 180

原创 模拟实现strchr

#include<stdio.h>#include<assert.h>char *my_strchr(const char *arr, char ch){ assert(arr); while (*arr != '\0') { if (*arr == ch) { return arr; } arr++; } return NULL;...

2018-05-23 17:15:06 143

原创 模拟实现strstr

#include<stdio.h>#include<assert.h>char *my_strstr(const char *str1, const char *str2){ assert(str1); assert(str2); char *cp = (char*)str1; char *substr = (char*)str2; char *s1 = N...

2018-05-23 17:02:57 127

原创 模拟实现strcat

#include<stdio.h>#include<assert.h>char *my_strcat(char *dest, const char *src){ char *ret = dest; assert(dest != NULL); assert(src != NULL); while (*dest) { dest++; } while (*...

2018-05-23 16:48:25 131

原创 模拟实现srccmp

#include<stdio.h>#include<assert.h>#include<windows.h>char *my_strcpy(char *dest, const char *src){ char *ret = dest; assert(dest!=NULL); assert(src != NULL); while (*dest++=...

2018-05-23 16:41:46 145

原创 使用main函数的参数,实现一个整数计算器,程序可以接受三个参数,第一个参数“-a”选项执行加法,“-s”选项执行减法,“-m”选项执行乘法,“-d”选项执行除法,后面两个参数为操作数。 例如:命令

#include <stdio.h> #include <string.h> #include <stdlib.h> int main(int argc, char* argv[]) { int ret = 0; if (argv[1][0] == '-...

2018-05-20 17:01:12 165

原创 日本某地发生了一件谋杀案,警察通过排查确定杀人凶手必为4个嫌疑犯的一个。以下为4个嫌疑犯的供词。 A说:不是我。 B说:是C。 C说:是D。 D说:C在胡说 已知3个人说了真话,1个人说的是

#include<stdio.h>#include<windows.h>#include<stdlib.h>int main(){ int M; for (M = 'A'; M <= 'D'; M++){ if (((M != 'A') + (M == 'C') + (M == 'D') + (M != 'D')) == 3)//题干中说...

2018-05-17 23:01:50 318

原创 杨辉三角。

杨辉三角,是二项式系数在三角形中的一种几何排列,在中国南宋数学家杨辉1261年所著的《详解九章算法》一书中出现。杨辉三角如图:杨辉三角,其实质是二项式为(a+b)的n次方展开后各项系数排成的三角形,它的特点是左右两边全是1,从第2行开始,中间的每一行数是上一行里相邻两个数之和。#include<stdio.h>#include<windows.h>#pragma war...

2018-05-17 22:56:58 481

原创 日本某地发生了一件谋杀案,警察通过排查确定杀人凶手必为4个嫌疑犯的一个。以下为4个嫌疑犯的供词。 A说:不是我。 B说:是C。 C说:是D。 D说:C在胡说 已知3个人说了真话,1个人说的是

#include<stdio.h>#include<windows.h>#include<stdlib.h>int main(){ int M; for (M = 'A'; M <= 'D'; M++){ if (((M != 'A') + (M == 'C') + (M == 'D') + (M != 'D')) == 3)//题干中说...

2018-05-17 22:07:52 221

原创 5位运动员参加了10米台跳水比赛,有人让他们预测比赛结果 A选手说:B第二,我第三; B选手说:我第二,E第四; C选手说:我第一,D第二; D选手说:C最后,我第三; E选手说:我第四,A

#include<stdio.h>#include<windows.h>#include<stdlib.h>int main(){ int a = 0, b = 0, c = 0, d = 0, e = 0; for (a = 1; a <= 5; a++){ for (b = 1; b <= 5; b++){ for (c ...

2018-05-17 21:53:31 116

原创 喝汽水,1瓶汽水1元,2个空瓶可以换一瓶汽水,给20元,可以多少汽水。编程实现。

#include<stdio.h>#include<stdlib.h>#include<windows.h>int He_qishui(int n){ int total = n; while (n > 1) { total =total+ n / 2; n = n / 2 + n % 2; } return total;...

2018-05-16 22:55:25 263

原创 喝汽水,1瓶汽水1元,2个空瓶可以换一瓶汽水,给20元,可以多少汽水。编程实现

#include<stdio.h>#include<windows.h>int HeQiShui(int M){ static int flag = 0; if (2 * M + flag < 2) { return 0; } if (M % 2 == 0) { return M + HeQiShui(M / 2); } else i...

2018-05-16 22:44:28 460

原创 模拟实现strcat

char *My_strcat(char *dest, const char*src){ char *ret = dest; assert(dest != NULL); assert(src != NULL); while (*dest) { dest++; } while ((*dest++ = *src++)) { ; } return ret;}strcat...

2018-05-13 16:28:18 187

原创 模拟实现strcpy

char *My_strcpy(char *dest, const char*src){ char*ret = dest; assert(dest != NULL); assert(src != NULL); while ((*dest++ = *src++)) { ; } return ret;}strcpy(dest,src)函数是把从src地址开始且含有NULL结束符...

2018-05-13 16:20:10 141

原创 使用可变参数,实现函数,求函数参数的最大值。

#include<stdio.h>#include<stdlib.h>#include<stdarg.h>#include<windows.h>int Max(int n, ...){ int i = 0; int Max = 0; va_list arg; va_start(arg, n); for (i = 0; i &lt...

2018-05-13 16:09:23 410

原创 使用可变参数,实现函数,求函数参数的平均值。

#include<stdio.h>#include<stdlib.h>#include<stdarg.h>int average(int n, ...){ va_list arg; int i = 0; int sum = 0; va_start(arg, n); for (i = 0; i < n; i++) { sum += v...

2018-05-13 16:00:18 1026

原创 递归方式实现打印一个整数的每一位

#include<stdio.h>#include<stdlib.h>#include<windows.h>#pragma warning(disable:4996)void print(int n){ if (n > 9){ print(n/10); } printf("%d\n", n % 10);}int main()...

2018-05-13 15:46:48 195

原创 递归和非递归分别实现求n的阶乘

#include<stdio.h>#include<stdlib.h>#include<windows.h>#pragma warning(disable:4996)int factorial(int n){ if (n == 0 || n == 1){ return 1; } else{ return n*factorial(n - 1...

2018-05-13 15:41:24 584

原创 写一个递归函数DigitSum(n),输入一个非负整数,返回组成它的数字之和

#include<stdio.h>#include<stdlib.h>#include<windows.h>#pragma warning(disable:4996)int Sum(int a){ int sum = 0; int m = 0; if (a != 0) { m = a % 10; //取高位 a = a / 10; //...

2018-05-13 15:26:56 233

原创 编写一个函数实现n^k,使用递归实现

#include<stdio.h>#include<stdlib.h>#include<windows.h>int JieCheng(int n, int k){ if (k == 0){ return 1; } if (k == 1){ return n; } else{ return n*JieCheng(n, k - 1);...

2018-05-13 15:17:07 260

原创 递归和非递归分别实现求第n个斐波那契数。

递归方法:#include<stdio.h>#include<stdlib.h>#include<windows.h>#pragma warning(disable:4996)int fib(int n){ while (n < 2) return n; while (n >= 2) return fib(n - 1) + fi...

2018-05-13 15:05:20 167

原创 实现一个函数,可以左旋字符串中的k个字符。 ABCD左旋一个字符得到BCDA ABCD左旋两个字符得到CDAB

#include<stdio.h>#include<windows.h>#include<stdlib.h>#pragma warning(disable:4996)void Move(char *p, int num){ int i = 0; for (i = 0; i < num; i++) { char tmp = *p; i...

2018-05-13 14:35:02 131

原创 从简单的c程序来看函数调用和栈帧结构

什么是栈帧?我们知道每一次函数调用都是一个过程。这个过程我们通常称之为:函数的调用过程。这个过程主要为函数开辟栈空间,用于本次函数调用中临时变量的保存、现场保护。这块栈空间我们称之为函数栈帧。我们用一段简单的c程序来具体了解下函数栈帧:c程序:#include<stdio.h>#include<windows.h>#include<stdlib.h>int My...

2018-05-11 13:57:31 621

原创 有一个二维数组. 数组的每行从左到右是递增的,每列从上到下是递增的. 在这样的数组中查找一个数字是否存在。

#include<stdio.h>#pragma warning(disable:4996)#define ROW 3#define COL 3int Yang(int arr[ROW][COL], int value){ int i = 0; int j = COL - 1; int tmp = arr[i][j]; while (1) { if (tmp == value) {...

2018-05-04 16:46:46 211

原创 调整数组使奇数全部都位于偶数前面。 题目: 输入一个整数数组,实现一个函数,来调整该数组中数字的顺序使得数组中所有的奇数位于数组的前半部分,所有偶数位于数组的后半部分。

#include<stdio.h>#include<stdlib.h>void swap(int *arr, int sz){ int i = 0; int j = sz - 1; for (i = 0; i != j; i++){ if (arr[i] % 2 != 0) continue; else { int tmp; tmp = arr[i]; ...

2018-05-04 15:57:53 168

空空如也

空空如也

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

TA关注的人

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