自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 数组操作.c

数组中所有数都是成对出现,只有两个数只出现一次,找出这两个数int main(){ int a[] = {2,4,6,5,4,2,6,3}; int len = sizeof(a)/sizeof(int); int num = 0; int num1 = 0; int num2 = 0; // 1、两个数的异或结果 int i = 0; for (i = 0; i &...

2019-01-04 19:27:34 147

原创 多路复用.c

#include <stdio.h>#include <sys/types.h>#include <sys/socket.h>#include <string.h>#include <unistd.h>#include <arpa/inet.h>#include <stdlib.h>#include

2019-01-02 20:21:29 518

原创 quicksort.c

#include <stdio.h>// 交换函数void mySwap(int *a, int i, int j){ int temp = a[i]; a[i] = a[j]; a[j] = temp;}// 打印函数void myPrint(int *a, int len){ int i; for (i = 0; i < len; i++) ...

2018-12-28 20:32:33 423

原创 生产者与消费者模型.c

#include <stdio.h>#include <string.h>#include <semaphore.h>#include <pthread.h>struct _data{ char buf[20]; // 缓冲区中的数据 sem_t full; // 控制消费者进入 sem_t empty; // 控制生...

2018-12-27 20:47:32 190

原创 定时器.c

#include <stdio.h>#include <signal.h>#include <unistd.h>void handle_signal(int signum){ if (signum == SIGALRM) { printf("hello\n"); alarm(2); // 重置定时时间 }}int main()...

2018-12-25 20:42:31 518

原创 选择排序.c

#include <stdio.h>// 交换函数void mySwap(int *a, int i, int j){ int temp = a[i]; a[i] = a[j]; a[j] = temp;}// 打印函数void myPrint(int *a, int len){ int i; for (i = 0; i < len; i++) ...

2018-12-24 20:18:31 76

原创 选择排序.c

#include <stdio.h>// 交换函数void mySwap(int *a, int i, int j){ int temp = a[i]; a[i] = a[j]; a[j] = temp;}// 打印函数void myPrint(int *a, int len){ int i; for (i = 0; i &l...

2018-12-24 12:02:45 88

原创 冒泡排序改进之鸡尾酒排序.c

#include <stdio.h>// 交换函数void mySwap(int *a, int i, int j){ int temp = a[i]; a[i] = a[j]; a[j] = temp;}// 打印函数void myPrint(int *a, int len){ int i; for (i = 0; i < len; i++) ...

2018-12-21 16:50:30 189

原创 九大排序之冒泡排序.c

#include <stdio.h>void mySwap(int *a, int i, int j){ int temp = a[i]; a[i] = a[j]; a[j] = temp;}void mySort(int *a, int len){ int i, j; for (i = 0; i < len-1; i++) // 将最大元...

2018-12-20 19:49:26 89

原创 非递归实现二叉树遍历.c

#include "BTree.h"#include <stdio.h>#include "LinkQueue.h"#include "LinkStack.h"void printData(BTreeNode* node){ printf ("%c\n", node->data);}void pre_order(BTreeNode *root){ if ...

2018-12-17 22:11:52 89

原创 swap.c

#include <stdio.h>void swap(int &a, int &b){ if (a != b) { a ^= b; b ^= a; a ^= b; }}int main(){ int a = 1; int b = 2; swap(a, b); printf("a = %d, b = %d\n", a, ...

2018-12-14 20:03:56 301 1

原创 swap.c

#include <stdio.h>void swap(int* a, int* b){ int temp; temp = *a; *a = *b; *b = temp;}int main(){ int a = 1; int b = 2; int arr[5] = {0, 1, 2, 3, 4}; swap(&a, &b); swa...

2018-12-14 19:42:31 208

原创 静态库制作

静态库: 要被包含到源程序中的库 优点:运行速度快 缺点:占用系统资源比较多 使用的场合: 对时间要求很高的场合静态库的制作:1、把所有的源程序(.c文件)制作成目标文件(.o 文件) gcc -c mul.c -o mul.o gcc -c sub.c -o sub.o gcc -c add.c -o add.o ...

2018-12-14 09:26:42 124

原创 十进制转八进制.c

#include <stdio.h>void fun(int m){ if (m == 0) return; int temp = m % 8; fun(m /= 8); printf("%d", temp);}int main(){ printf("请输入十进制数:"); int a; scanf("%d", &a); fu...

2018-12-12 19:36:25 4405 1

转载 输出系统当前时间.c

#include <stdio.h>#include <time.h>int main(){ time_t t; struct tm* lt; time (&t); lt = localtime(&t); printf("%d/%d/%d %d:%d:%d\n",lt->tm_year+1900, lt->tm_mon+...

2018-12-12 17:06:48 369

原创 字符串简单转换.c

/* 给你一个字符串 1a2b3c把里面的数字给显示出来 i[]把里面的字母转大写显示出来 ch[] */#include <stdio.h>#include <string.h>int main(){ char str[] = "0a1a2b3c9z"; int len = strlen(str); int in[5]; char c...

2018-12-12 16:53:14 164

原创 压缩数组.c

已知一维整型数组a中的数已按由小到大的顺序排列,编写程序,删去一维数组中所有相同的数,使之只剩一个。#include <stdio.h>int main(){ int arr1[] = {1,1,2,3,3,3,4,4,4,4,5}; int len1 = sizeof arr1 / sizeof(int); int arr2[len1]; int len2 ...

2018-12-12 16:22:53 1205

原创 统计单词个数.c

统计一个英文句子中含有英文单词的个数,单词之间用空格隔开。#include <stdio.h>#define SPACE ' 'int count_word(char* str){ if (str == NULL) return -1; int count = 0; char* p = str; while (*p++ != '\0') if (...

2018-12-12 15:14:51 982

转载 复数和.c

#include <stdio.h>typedef struct _complex // 以结构体的形式定义一个复数{ int re; int im;}Complex;/* 函数名:add_complex(Complex* com1, Complex* com2)参数列表:结构体指针com1,com2函数功能:两个复数以结构体的形式相加返回值:返回一个结构体 ...

2018-12-12 14:35:06 333

原创 查找子串在母串的位置.c

题目:请写一个函数,实现从一个字符串中,查找另一个字符串的位置,           如strstr("12345", "34")返回值为2,即在2号位置找到字符串“34#include <stdio.h>int length(char* pstr){ int len = 0; while (*pstr++ != '\0') len++; return ...

2018-12-12 11:37:17 967

原创 随机生成10位数QQ号.c

// 随机生成十位数的QQ号,首位数只能为1,2,3#include <stdio.h>#include <stdlib.h>#include <time.h>void random_num(int*, int); // 输出指定位数的随机数long arr_to_int(int*, int); // 数组转整型int main(){...

2018-12-11 20:58:03 5427

原创 字符串转定常数.c

#include <stdio.h>#include <string.h>// 将一个不定长的字符串转换为一个定长的数字// 输入:字符串// 输出:16位数字 /* 转换格式:将字符串分成n组,每组16个字符, 将n组字符串相应位置的字符相加,如果值不是个位数, 则各个位再进行相加,直到为个位数为止, 最终得出的16个数字即要求输出的数字...

2018-12-10 18:18:13 261

原创 ctype.h

2018-12-07 19:32:56 146 1

原创 cypher.c

// 替换输入的字母,非字母字符保持不变#include <stdio.h>#include <ctype.h> // 包含isalpha()的函数原型int main(){ char ch; while ((ch = getchar()) != '\n') { if (isalpha(ch)) // 如果是一个字母 putchar...

2018-12-06 21:16:57 179

原创 strcpy函数实现.c

#include <stdio.h>#include <string.h>void my_strcpy(char* str1, char* str2){ int len1 = strlen(str1); int len2 = strlen(str2); int i; for (i = 0; i < len1; i++) str1[i] = st...

2018-12-06 18:09:02 176

原创 strcat函数实现.c

#include <stdio.h>#include <string.h>void my_strcat(char* str1, char* str2){ int len1 = strlen(str1); int len2 = strlen(str2); int len = len1 + len2; int i; for (i = 0; i < l...

2018-12-06 17:38:58 712

原创 strlen函数实现.c

#include <stdio.h>int my_strlen(const char* src){ int len = 0; while(*src++ != '\0') len++; return len;}int main(){ char arr[] = "Hello C language!"; printf ("len:%d\n", my_s...

2018-12-06 15:00:28 102

原创 抓交通肇事犯.c

// 一辆卡车违反交通规则,撞人后逃逸。现场有三个人目击事件,但都没有记住// 车号,只记得车号的一些特征。甲说:牌照的前两位数是相同的;乙说:牌照// 的后两位是相同的,但与前两位不同;丙说:四位的车号刚好是一个整数的平// 方。请根据以上线索求出车号。#include <stdio.h>#include <math.h> int main() ...

2018-11-29 13:51:21 1164

原创 打鱼还是晒网.c

// 三天打鱼两天晒网#include <stdio.h>struct date { int year; int month; int day;};days(day) struct date day;{ static int day_tab[2][13] = {{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 3...

2018-11-29 13:14:21 186

原创 递归法求和.c

// 用递归法求1~100的和#include <stdio.h>unsigned int my_sum(unsigned int n){ if (n <= 0) return 0; if (n == 1) return 1; else return n + my_sum(n-1);}int main(){ int a = my_sum(1...

2018-11-28 13:23:54 564

原创 借书方案知多少.c

// 借书方案知多少// 小明有五本新书,要借给A,B,C三位小朋友,若每人每次只能借一本书,// 则可以有多少种不同的借法?/* 问题分析与算法设计: 首先对五本书从1至5进行编号,然后使用穷举的方法,假设三个人分别借 这五本书中的一本,当三个人所借的书的编号都不相同时,就是满足题意 的一种借法。*/#include <stdio.h>int main()...

2018-11-27 16:43:40 594

原创 阶乘末尾 0 的个数.c

// 阶乘尾数零的个数// 100!的末尾有多少个0?/* 问题分析和算法设计: 首先分析在100!结果值的末尾产生0的条件。不难看出:一个整数 若含有一个因子5则必然会在求100!时产生一个0。因此问题转化为 求1到100这100个整数中包含了多少个因子5。若整数N能被25整除, 则N包含2个因子5;若整数N能被5整除,则N包含一个因子5。*/#include &lt...

2018-11-27 15:54:21 1411

原创 公共子串.c

// 题目:编程实现查找两个字符串的最大公共子串// 示例:"aocdfe"和"pmcdfa"最大公共子串为"cdf" #include <stdio.h>#include <string.h>int main1(){ char str1[] = "aocdfe"; char str2[] = "aadapmcdfa"; i

2018-11-27 15:21:54 145

原创 测试.c

// 测试计算机是大端模式还算是小端模式#include <stdio.h>int func(){ union { unsigned int a; unsigned char c; }test; test.a = 0x12345678; return (test.c == 0x78);}int main(){ if (func() == ...

2018-11-27 11:29:08 202

原创 乘法表.c

#include<stdio.h>int main(){ int i,j; for(i = 1; i <= 9; i++) { for(j = 1; j <= i; j++) { printf("%d*%d=%d\t", i, j, i*j); } printf("\n"); } return 0;}运行结果:...

2018-11-26 21:01:47 306

原创 两次逆序.c

// 将 you are from shanghai 倒序成 shanghai from are you#include <stdio.h>int strLen(char *pStr){ if (pStr == NULL) return -1; int len = 0; while (*(pStr++)) len++; return len;}...

2018-11-26 18:19:21 114

原创 趣味编程6.c

// 高次方数的尾数// 求13的13次方的最后三位数。/* 问题分析与算法设计 解本题最直接的方法是:将13累乘13次后截取最后三位即可。 但是由于计算机所能表示的整数范围有限,用这种“正确”的算法 不可能得到正确的结果。事实上,题目仅要求后三位的值,完全没有 必要求13的13次方的完整结果。 研究乘法的规律会发现:乘积的最后三位的值只与乘数和被乘数的后三位 有关,与...

2018-11-26 11:46:42 110

原创 趣味编程5.c

// 求最大约数// 问555555的约数中最大的三位数是多少?#include <stdio.h>int main(){ int a = 555555; int i = 999; for (i = 999; i > 99; i--) { if (a % i == 0) { printf ("%d\n",i); break; ...

2018-11-26 10:58:02 68

原创 随机数.c

#include <stdio.h>int main(){ int a[10] = {0}; int i = 0; srand(time(NULL)); for (i = 0; i < 10; ++i) { a[i]= rand() % 10; // 1 - N } for...

2018-11-26 09:28:17 203

原创 趣味编程4.c

// 歌星大奖赛:// 在歌星大奖赛中,有10个评委为参赛选手打分,分数从1~100分。// 选手最后得分为:去掉一个最高分和一个最低分其余8个分数的平均值。/* 问题分析与算法设计 这个问题的算法十分简单, 但要注意在程序中判断最大最小值的变量是如何赋值的。*/#include <stdio.h>int main(){ float score = ...

2018-11-25 14:56:58 96

空空如也

空空如也

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

TA关注的人

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