![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C语言
w517565244live
这个作者很懒,什么都没留下…
展开
-
十进制转二进制
从屏幕输入10进制,程序需要输出对应的二进制数据。例如:输入: 12.25输出:1010.01。原创 2022-11-19 19:23:05 · 156 阅读 · 0 评论 -
简单的ls命令
ls简单命令的实现原创 2022-11-09 20:25:08 · 126 阅读 · 0 评论 -
Linux 线程池的实现
linux环境下的线程池原创 2022-11-09 19:36:20 · 152 阅读 · 0 评论 -
牛客网反转链表
反转链表原创 2022-09-03 21:06:30 · 102 阅读 · 0 评论 -
汉诺塔问题的递归算法
汉诺塔问题的递归算法void move(int a, int b){ printf("move %d --> %d \n", a, b);}void hanoi(int n, int a, int b, int c){ if (n>0) { hanoi(n-1, a, c, b); move(a, b); hanoi(n-1, c, b, a); }}原创 2021-06-03 21:03:41 · 99 阅读 · 0 评论 -
链表的合并
链表的合并#include <stdio.h>#include <stdlib.h>typedef struct node { int data; struct node * next;}node;void reverse(node *head) { node *p = head->next; node *n; head->next = NULL; while(p != NULL) { n = p原创 2021-06-03 21:01:52 · 44 阅读 · 0 评论 -
找二叉树节点的双亲
找二叉树节点的双亲#include <stdio.h>typedef struct node { int data; struct node *lchild,*rchild;} bitree;bitree *q[20];int r=0;int flag=0;void Preorder(bitree *bt, char x){ if (bt!=0 && flag==0){ if (bt->data==x) {原创 2021-06-03 21:01:31 · 1769 阅读 · 1 评论 -
strcmp()函数的实现
问题:字符串比较,分别从键盘读入两个字符串stra和strb,比较这两个字符串的大小,例如输入:abcabb输入为:abc > abb.int strcmp(const char *str1, const char *str2){ int i = 0; for (i = 0; ; i++) { if (str1[i] == str2[i]) { continue; } else { return原创 2021-06-03 21:00:56 · 160 阅读 · 0 评论 -
结构体的嵌套
问题:从键盘输入学生的信息,并统计学生的成绩实现#include <stdio.h>#include <stdlib.h>#include <math.h>#include <string.h>//-----------------------------------------------------/** 结构体的嵌套 *///---------------------原创 2021-06-03 21:00:23 · 49 阅读 · 0 评论 -
memset()和bzero()的实现
问题:实现memset2() 和bzero2()void * memset2(void *vp, Byte value, int size){ Byte *bp = (Byte *)vp; int i = 0; for (i=0; i<size; i++) { bp[i] = value; } return vp;}void bzero2(void *vp, int size){ memset2(vp, 0x0, siz原创 2021-06-03 21:00:04 · 83 阅读 · 0 评论 -
局部变量(c语言)
在c语言中,非静态的局部变量默认是auto类型的#include <stdio.h>#include <stdlib.h>int addOne() { int number = 0; number = number + 1; return number;}int main(){ printf("第一次调用:%d\n", addOne()); printf("第二次调用:%d\n", addOne()); return原创 2021-06-03 20:59:47 · 84 阅读 · 0 评论 -
什么是指针
问题:什么是指针?如何定义并访问指针?指针的本质是什么?#include <stdio.h>#include <stdlib.h>int main(){ int number = 0; /// 定义一个整型变量 int *pNumber = &number; /// 定义一个指针变量,并将其赋值为number的地址 *pNumber = 100; /// 通过指针去修改变量的值 printf("原创 2021-05-31 12:07:46 · 49 阅读 · 0 评论 -
指针参数(C语言)
/******************************************************** * 指针作为参数 * *******************************************************/#include <stdio.h>#include <stdlib.h>/*** * 修改局部变量,将 */int modifyLoca原创 2021-05-31 12:07:27 · 567 阅读 · 0 评论 -
指针、数组、结构体练习
#include <stdio.h>#include <stdlib.h>#include <string.h>/*************************************************************1. 实现swap函数, 实现数a和数b的交换 int swap(int *a, int *b);2. 数组求和,将结果通过参数s返回 int sum(int array[], int n, int *s); /原创 2021-05-31 12:06:48 · 133 阅读 · 0 评论 -
转义字符(escape)
转义字符 (escape)#include <stdio.h>#include <stdlib.h>int main(){ float salary; printf("\aEnter your desired monthly salary:"); printf(" $_______\b\b\b\b\b\b\b"); // 7个退格使得光标向左移动7个位置 scanf("%f", &salary); // .2f原创 2021-05-31 12:06:15 · 419 阅读 · 0 评论 -
从键盘读一个数
#include <stdio.h>#include <stdlib.h>int main(){ int number = 0; scanf("%d", &number); while (number < 6) { printf("Your number is to small.\n"); scanf("%d", &number); } return 0;}原创 2021-05-31 12:05:52 · 88 阅读 · 0 评论 -
实参的类型转换
#include <stdio.h>#include <stdlib.h>void pound(int n); // ANSI 函数原型声明int main(void){ int times = 5; char ch = '!'; // ASCII 33 float f = 6.0f; pound(times); pound(ch); pound(f); return 0;}原创 2021-05-31 11:03:01 · 59 阅读 · 0 评论 -
强制类型转换
#include <stdio.h>#include <stdlib.h>int main(){ int nice = 0; nice = 1.6 + 1.7; printf("nice is: %d\n", nice); nice = (int)1.6 + (int)1.7; printf("nice is:%d\n", nice); return 0;}原创 2021-05-31 11:02:40 · 51 阅读 · 0 评论 -
自动类型转换
/*** * convert.c -- 自动类型转换*/#include <stdio.h>#include <stdlib.h>int main(){ char ch; int i; float fl; fl = i = ch = 'C'; printf("ch = %c, i = %d, fl = %2.2f\n", ch, i, fl); ch = ch + 1; i = fl + 2 * ch;原创 2021-05-31 11:02:20 · 90 阅读 · 0 评论 -
数组逆序(C语言)
问题:数组逆序,从键盘读入一个字符串,输出该字符串的逆序例如输入:abc则输出:cba实现:char* reverse(char *str) { int length = strlen(str); int i = 0; int j = length - 1; char tmp = 0; for (; i < j; i++, j--) { tmp = str[i]; str[i] = str[j]; st原创 2021-05-31 11:01:48 · 256 阅读 · 0 评论 -
strncmp()函数的实现
实现:int strncmp(const char *str1, const char * str2, int n){ int i = 0; for (i=0; i<n; i++) { if (str1[i] == str2[i]) { continue; } else { return str1[i] - str2[i]; } } return 0;}测试:in原创 2021-05-28 10:47:14 · 279 阅读 · 0 评论 -
字符串查找
问题:字符串查找,分别输入字符串和子字符串,输出字符串的起始位置例如输入: aabbccbb则输出: 2实现:int find(const char *str, const char *substr){ int i = 0; int length = strlen(str); int subLength = strlen(substr); for (i=0; i<length-subLength+1; i++) { int result =原创 2021-05-28 10:46:46 · 85 阅读 · 0 评论 -
strlen()函数的实现
问题:求一个字符串的长度,其函数的原型为 unsigned strlen(const char *);,要求从键盘读入一个字符串,该字符串的长度小于255,输出字符串的长度。实现:unsigned strlen(const char *str){ unsigned i = 0; for(i=0; str[i]!='\0'; i++); return i;}测试:int testStrlen() { char str[256] = {0}; print原创 2021-05-28 10:45:41 · 83 阅读 · 0 评论 -
指针作为返回参数-堆
/**************************************************** * 使用指针作为返回参数,返回堆变量的地址 ***************************************************/#include <stdio.h>#include <stdlib.h>int * add(int number1, int number2) { int * sum = (int *) malloc(s原创 2021-05-28 10:44:48 · 69 阅读 · 0 评论 -
指针作为函数的返回值-栈
/******************************************************** * 指针作为返回值返回 *******************************************************/#include <stdio.h>#include <stdlib.h>int * add(int number1, int number2){ int sum = number1 + number2;原创 2021-05-28 10:43:28 · 144 阅读 · 0 评论 -
栈(stack)溢出
/***************************************************** * 我们知道局部变量和函数调用的上下文是保存在栈里的 * 而栈的空间是有程序运行之初有操作系统分配的,且其 * 大小是固定的,有没有办法让栈溢出 ? * 答案是大数组 * 我们编程的时候, 又应该如何避免栈溢出? * 避免在在函数内部使用大数组,非要使用的情况下可以 * 使用全局的大数组或者malloc()动态申请堆空间的来代替 ********************原创 2021-05-28 10:42:59 · 100 阅读 · 0 评论 -
指针的操作
/********************************************************* * 指针的操作 ********************************************************/#include <stdio.h>#include <stdlib.h>int main(){ int numbers[] = {100, 200, 300, 400, 500, 600}; int原创 2021-05-28 10:41:43 · 57 阅读 · 0 评论 -
静态(static)变量
#include <stdio.h>#include <stdlib.h>/*** * static 定义的变量为静态变量的作用域各不相同 * 例如: * 函数内部的静态变量的作用域在函数内部 * 函数外部的静态变量的作用域为该变量所在的文件 * 但是静态变量的生存周期和全局变量是一致的,即都是整个程序运行期间 * ?为什么会这样? * 其根本原因是全局变量、局部静态变量和全局静态变量的存储位置都是全局变量区 * 使用staitc修饰,只不过是为了限制这个变量的作原创 2021-05-28 10:40:33 · 71 阅读 · 0 评论 -
打印对角矩阵
#include <stdio.h>#include <stdlib.h>int setDiagonal(int matrix[][256], int n) { int i = 0; for (i=0; i<n; i++) { matrix[i][i] = matrix[i][n-i-1] = 1; }}int main(){ int matrix[256][256] = {0}; int n = 0;原创 2021-05-28 10:39:13 · 256 阅读 · 0 评论 -
三维坐标两点之间的距离
#include <stdio.h>#include <stdlib.h>#include <math.h>struct point3D { int x; int y; int z;};double distance3D(struct point3D startPoint, struct point3D endPoint){ int sum = 0; // 保存平方和 sum += pow(endPoint.x -原创 2021-05-28 10:38:09 · 1708 阅读 · 0 评论 -
删除数组中所有值为x的元素
问题:长度n的顺序表L,时间复O(n),空间复O(i),删除所有值为x的元素void delete_x(SqList * L, ElemType x){ int k = 0; for(int i = 0; i<L->length; i++){ if(L->data[i] == x){ k++; }else{ L->data[i-k] = L->data[i]; }原创 2021-05-27 16:23:29 · 1484 阅读 · 0 评论