自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 C++的第一节入门

C++第一节:入门1:C++命名空间在C++中解决了C语言中的一些名字的命名冲突,导致程序崩溃,或者运行失败。命名空间很好的解决了这些问题。2:命名空间的定义:在定义命名空间时需要用到namespace这个关键字后接命名空间的名字,然后接大括号,其中为命名空间的成员。eg:正如图所示,命名空间中可以定义变量,数组,还有函数。在同一...

2019-03-22 18:08:52 167

原创 C语言:一组数据中只有一个数字出现了一次,其他所有数字都是成对出现的。

#include<stdio.h>#include<stdlib.h>int main(){ int arr[7] = { 1, 1, 2, 2, 3, 3, 4 }; int ret = 0; int i = 0; for (i = 0; i < 7; i++) {  ret=ret^arr[i]; } printf("%d", ret); ...

2019-01-18 16:43:01 194

原创 C语言:不使用(a+b)/2这种方式,求两个数的平均值。

#include<stdio.h>#include<stdlib.h>int main(){ int a = 15; int c = 205; int b = (c - a) / 2 + a; printf("%d", b); system("pause"); return 0;}

2019-01-18 16:32:31 276

原创 C语言:函数的返回值value的二进制位模式从左到右翻转后的值

unsigned int reverse_bit(unsigned int value){ unsigned int i = 0; unsigned int ret = 0; unsigned int tmp = 0; unsigned int x = 0; for (i = 0; i < 32; i++) {     tmp = ret;  if ((value >...

2019-01-18 16:28:08 427

原创 C语言:打印杨辉三角

//在屏幕上打印杨辉三角。//1//1 1//1 2 1//1 3 3 1#include<stdio.h>#define x 6#define y 6int main(){ int i = 0; int j = 0;//i为行j为列 int arr[x][y] = {0}; for (i = 0; i < 2; i++) {  for (j =...

2019-01-18 14:48:26 103

原创 C语言:凶杀案

//日本某地发生了一件谋杀案,警察通过排查确定杀人凶手必为4个//嫌疑犯的一个。以下为4个嫌疑犯的供词。//A说:不是我。//B说:是C。//C说:是D。//D说:C在胡说//已知3个人说了真话,1个人说的是假话。//现在请根据这些信息,写一个程序来确定到底谁是凶手。#include<stdio.h>#include<stdlib.h>int main(...

2019-01-16 17:54:21 241

原创 C语言:5位运动员参加了10米台跳水比赛,请编程确定比赛的名次。

////5位运动员参加了10米台跳水比赛,有人让他们预测比赛结果//A选手说:B第二,我第三;//B选手说:我第二,E第四;//C选手说:我第一,D第二;//D选手说:C最后,我第三;//E选手说:我第四,A第一;//比赛结束后,每位选手都说对了一半,请编程确定比赛的名次。#include<stdio.h>#include<stdlib.h>int ma...

2019-01-16 14:09:03 356

原创 C语言:两个int(32位)整数m和n的二进制表达中,有多少个位(bit)不同

#include<stdio.h>#include<stdlib.h>//两个int(32位)整数m和n的二进制表达中,有多少个位(bit)不同int bit_compare(int n, int m){ int i = 0; int count = 0; for ( i = 0; i < 32; i++) {  if (((n >> i...

2019-01-15 18:03:29 241

原创 C语言://输出一个整数的每一位。

//输出一个整数的每一位。#include<stdio.h>#include<stdlib.h>void LYJ(int x){ int n = x % 10; while (x != 0) {  n = x % 10;  x = x / 10;  printf("%d", n); }}int main(){ int m = 2048; L...

2019-01-15 17:45:37 792

原创 C语言:获取一个数二进制序列中所有的偶数位和奇数位

//获取一个数二进制序列中所有的偶数位和奇数位,//分别输出二进制序列。#include<stdio.h>#include<stdlib.h>void test(int x){ int i = 0; printf("奇数位:"); for (i = 1; i <= 32; i++) {  if (i%2==0)  {   if (((x &g...

2019-01-15 17:14:28 421

原创 C语言:写一个函数返回参数二进制中 1 的个数

#include<stdio.h>#include<stdlib.h>////写一个函数返回参数二进制中 1 的个数//比如: 15 0000 1111 4 个 1//程序原型://int count_one_bits(unsigned int value)//{// // 返回 1的位数//}//int count_one_bits(unsigned i...

2019-01-15 16:52:52 132

原创 C语言:打印出一个整数的每一位

#include<stdio.h>#include<stdlib.h>void ergodic(int x){ if (x < 10) {  printf("%d", x); } else {  int n = x % 10;  printf("%d ", n);  ergodic( x / 10); }}int main(){ ...

2019-01-15 16:28:10 1069

原创 C语言:阶乘的递归与非递归算法

//递归和非递归分别实现求n的阶乘#include<stdio.h>#include<stdlib.h>//非递归//int test(int x)//{// int i = 0;// int sum = 1;//// for (i = 1; i <= x; i++)// {////  sum=sum*i;//  // }// retur...

2019-01-15 15:44:27 926

原创 C语言:strlen的递归与非递归实现

//递归和非递归分别实现strlen#include<stdio.h>#include<stdlib.h>#include<assert.h>//非递归//int my_strlen(char* str)//{// assert(str != NULL);//// int count = 0;//// while (*str != '\0'...

2019-01-15 15:11:18 153

原创 C语言:字符串翻转的递归方法

////编写一个函数 reverse_string(char * string)(递归实现)//实现:将参数字符串中的字符反向排列。//要求:不能使用C函数库中的字符串操作函数。#include<stdio.h>#include<stdlib.h>#include<string.h>char* reverse_string(char*str){ ...

2019-01-15 14:45:10 1661

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

#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h> int test(int x){ int n = 0;  int sum = 0; if (x != 0) {  n = x % 10;  x = x / 10;    sum = n + test(x); ...

2019-01-14 16:13:16 179

原创 C语言:喝汽水

//一个数组中只有两个数字是出现一次,//其他所有数字都出现了两次。//喝汽水喝汽水,1瓶汽水1元,2个空瓶可以换一瓶汽水,//给20元,可以多少汽水。//编程实现。#include<stdio.h>#include<stdlib.h>int main(){ int empty = 20; int sum = 20; while (empty &gt...

2019-01-10 17:22:56 398

原创 C语言:找一个数组中只有两个数字是出现一次, //其他所有数字都出现了两次。

//一个数组中只有两个数字是出现一次,//其他所有数字都出现了两次。//找出这两个数字,编程实现。#include<stdio.h>#include<stdlib.h>int main(){ int i = 0; int a = 0; int b = 0; int c = 0; int arr[10] = { 1, 1, 2, 2, 3, 3, 4, ...

2019-01-10 17:15:11 147

原创 C语言:qsort排序的实现

/* qsort example */#include <stdio.h>      /* printf */#include <stdlib.h>     /* qsort */#include<string.h> struct S{ char name[20]; int age;}; /*int compare(const void*x,...

2019-01-10 16:49:40 554

原创 C语言:memmove的实现

#include<stdio.h>#include<stdlib.h>#include<string.h>#include<assert.h>void* my_memmove(void* dest, const void*str, size_t count){ assert(dest != NULL&str != NULL);...

2019-01-09 20:10:20 366

原创 C语言:memcpy的实现

#include<stdio.h>#include<stdlib.h>#include<string.h>#include<assert.h>void *my_memcpy(void *dest, const void *src, size_t n){ assert(dest != NULL&&src != NULL);...

2019-01-09 18:09:55 535

原创 C语言:strchr函数的实现

#define _CRT_SECURE_NO_WARNINGS//strchr#include<assert.h>#include<stdio.h>#include<stdlib.h>#include<string.h>char* my_strchr(char* str, int c){ while (*str != c) {  ...

2019-01-09 18:06:02 471

原创 C语言:strcat函数的实现

#define _CRT_SECURE_NO_WARNINGS//strcat#include<assert.h>#include<stdio.h>#include<stdlib.h>#include<string.h>int my_strcat( char *dest, const char *str){ assert(dest !...

2019-01-09 17:53:50 422

原创 C语言:strcmp函数的实现

#define _CRT_SECURE_NO_WARNINGS//strncmp#include<assert.h>#include<stdio.h>#include<stdlib.h>#include<string.h>int my_strcmp(const char *dest, const char *str){ assert(...

2019-01-09 17:48:18 1057

原创 C语言:strncmp函数的实现

int my_strncmp(const char *dest, const char *str, size_t n){ assert(dest != NULL&str != NULL); const char* d = dest; const char* s = str; while (n--) {  if (*dest++ < *str++)  {   retu...

2019-01-09 17:19:04 1670

原创 C语言:strncat函数的实现

#define _CRT_SECURE_NO_WARNINGS//strncat#include<assert.h>#include<stdio.h>#include<stdlib.h>#include<string.h> char* my_strncat( char*dest, const char* str, int count){...

2019-01-09 15:56:25 544

原创 C语言:strncpy函数模拟实现

//模拟实现strncpy#define _CRT_SECURE_NO_WARNINGS#include<assert.h>#include<stdio.h>#include<stdlib.h>#include<string.h>char* my_strncpy(char*dest, const char* str, int count)...

2019-01-09 15:16:32 287

原创 C语言:斐波那契契数列的实现,递归 与 非递归

#define _CRT_SECURE_NO_WARNINGS#include<stdlib.h>#include<stdio.h>//int fib(int n)//{// int f = 0;// if (n <= 2&&n>0)// {//  return 1;// }// else// {//  return fi...

2019-01-09 14:21:53 521 1

原创 C语言:用函数判断是否为素数

#define _CRT_SECURE_NO_WARNINGS//判断素数#include<stdlib.h>#include<stdio.h>#include<string.h>void LYJ(int x){ int i = 0; int flag = 0; for (i = 2; i < x; i++) {  if (x...

2019-01-07 19:12:04 2781 2

原创 C语言:关于数组的初始化,空置,逆转

#define _CRT_SECURE_NO_WARNINGS//4.//创建一个数组,//实现函数init()初始化数组、//实现empty()清空数组、//实现reverse()函数完成数组元素的逆置。//要求:自己设计函数的参数,返回值。#include<stdlib.h>#include<stdio.h>#include<string.h...

2019-01-07 18:21:59 256

原创 C语言:用函数判断是否为润年

#define _CRT_SECURE_NO_WARNINGS//实现一个函数判断year是不是润年#include<stdlib.h>#include<stdio.h>#include<string.h>int LYJ(int x){ if (x % 4 == 0 && x % 100 != 0 || x % 400 == 0)...

2019-01-07 16:39:24 750

原创 C语言:用函数实现两个数交换

#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>void swap(int x, int y){ x = x^y; y = x^y; x = x^y; printf("%d %d", x,y);}int main(){ int x = 0; int y = 0; int ret = 0; scanf("%d...

2019-01-07 16:27:37 2441

原创 C语言:用函数实现乘法表

#define _CRT_SECURE_NO_WARNINGS//实现一个函数,打印乘法口诀表,口诀表的行数和列数自己指定,//输入9,输出9 * 9口诀表,输入12,输出12 * 12的乘法口诀表。#include<stdio.h>void multables(int x){ int i = 0, j = 0, arr = 0; for (i = 1; i <...

2019-01-07 16:10:17 1615

原创 C语言:strstr函数的实现;

#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>#include<assert.h>const char* my_strstr(const char* dest,const char* str){ assert(str != NULL); assert(dest ...

2019-01-07 15:26:51 1384

原创 模拟strcpy与strlen

#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>#include<assert.h>#include<string.h>//size_t my_strlen(const char*str)//{// assert(str != NULL);// if...

2019-01-06 15:15:31 88

原创 C语言:输入大小写转换字母,数字除外

#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>int main(){ int c; while ((c = getchar()) != EOF) {  if (c >= 'a'&&c <= 'z')   printf("%c", c - 3...

2019-01-05 15:47:03 557

原创 C语言:编写代码模拟三次密码输入的场景。

#define _CRT_SECURE_NO_WARNINGS//编写代码模拟三次密码输入的场景。#include<stdio.h>#include<stdlib.h>int main(){ int password = 135725; int input = 0, m = 1; do {  printf("请输入密码\n");  scanf("%d"...

2019-01-05 15:16:55 211

原创 C语言:折半查找

#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>int Bisearch(int arr[], int key, int sz){ int right = sz-1, left = 0;//下标 int mid = 0; while (left <= right) {...

2019-01-05 15:06:58 207

原创 C语言:猜数字游戏

#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>#include<time.h>int main(){ while (1) {  int seed = 0, x = 0;  srand((unsigned)time(NULL));//  x = rand(...

2019-01-05 14:17:05 2081

原创 C语言:求Sn=a+aa+aaa+aaaa+aaaaa的前5项之和,其中a是一个数字, 例如:2+22+222+2222+22222

#include<stdio.h>#include<stdlib.h>int main(){ int i = 0 ,a = 0,sum=0,ret=0; scanf("%d", &a); /*a * 10 + a; a * 100 + a * 10 + a; a * 1000 + a * 100 + a * 10 + a;*/ for (i = 0...

2019-01-05 13:48:05 136

空空如也

空空如也

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

TA关注的人

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