当前位置:网站首页>【C 题集】of Ⅶ
【C 题集】of Ⅶ
2022-07-04 12:49:00 【InfoQ】
write in front
第三十一题→模拟实现strcat()函数
char *strcat(char *dest, const char *src)第三十二题→随机输入十个数字,数字按照从大到小排列
第三十三题→用一个函数在函数内部创建一个变量来交换两个值的变量
第三十四题→接收一个整型值(无符号形式),按照顺序打印出每一位。例如:1234,输出 1 2 3 4(递归的形式)
- 存在限制条件,当满足这个限制条件之后的时候,递归便会不再继续。
- 每次递归调用之后都会越来越接近这个限制条件。
第三十五题→模拟实现字符串函数打印长度,用递归的形式,不能创建临时变量
size_t strlen ( const char * str );
第三十一题→代码
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<assert.h>
char *My_strcat(char *dest, const char *src)
{
assert(dest && src != NULL);
char *ret = dest;
while (*dest != '\0')//'\0'的ASCLL码值就是0
{
dest++;
}
//dest指向的是'\0'
while (*dest++ = *src++)
{
;
}
return ret;
}
int main(void)
{
char arr1[20] = "hello C";
char arr2[20] = "yuyan";
printf("%s\n", My_strcat(arr1, arr2));
return 0;
}第三十二题→代码
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main(void)
{
int arr[10] = { 0 };
int i = 0;
int j = 0;
int k = 0;
puts("请输入数字:");
for (i = 0; i < 10; i++)
{
scanf("%d", &arr[i]);
}
for (i = 0; i < 10; i++)
{
for (j = 0; j < 10 - i - 1; j++)
{
if (arr[j] > arr[j + 1])
{
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
printf("program result:%d\n", arr[j]);
}
//比较相邻的元素。如果第一个比第二个大,就交换他们两个。
//每趟从第一对相邻元素开始,对每一对相邻元素作同样的工作,直到最后一对。
//针对所有的元素重复以上的步骤,除了已排序过的元素(每趟排序后的最后一个元素),直到没有任何一对数字需要比较
return 0;
}第三十三题→代码
#include<stdio.h>
void swap(int *x, int *y)
{
int tep = *x;
*x = *y;
*y = tep;
}
int main(void)
{
int a = 10;
int b = 20;
printf("交换之前:a=%d,b=%d\n", a, b);
swap(&a, &b);
printf("------------------\n");
printf("交换之后:a=%d,b=%d\n", a, b);
return 0;
}第三十四题→代码
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
void print(unsigned int number)
{
if (number > 9) //限制条件
{
print(number / 10); //调用这个函数,直到表达式为假执行下面语句,1234 123 12 1
}
printf("%d ", number % 10);
}
int main(void)
{
unsigned int number = 0;
printf("请输入数字:");
scanf("%u", &number);
print(number);
return 0;
}第三十五题→代码
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int My_strlen(char *str)
{
if (*str != '\0')
return 1 + My_strlen(1 + str);
else
return 0;
}
int main(void)
{
char arr[20] = {0};
printf("请输入字符:");
scanf("%s", &arr);
printf("str = %d\n", My_strlen(arr));
return 0;
}最后
边栏推荐
- Introduction to XML I
- Fs7867s is a voltage detection chip used for power supply voltage monitoring of digital system
- How to choose a technology stack for web applications in 2022
- After the game starts, you will be prompted to install HMS core. Click Cancel, and you will not be prompted to install HMS core again (initialization failure returns 907135003)
- 英视睿达冲刺科创板:年营收4.5亿 拟募资9.79亿
- C语言集合运算
- 美国土安全部部长警告移民“不要踏上危险的旅程”
- Source code compilation and installation of MySQL
- C basic supplement
- C language dormitory management query software
猜你喜欢
Three schemes to improve the efficiency of MySQL deep paging query

Interview disassembly: how to check the soaring usage of CPU after the system goes online?

Interviewer: what is the internal implementation of hash data type in redis?

源码编译安装MySQL

一次 Keepalived 高可用的事故,让我重学了一遍它

Detailed explanation of Fisher information quantity detection countermeasure sample code

Flet tutorial 03 basic introduction to filledbutton (tutorial includes source code) (tutorial includes source code)

Byte interview algorithm question

面试官:Redis中哈希数据类型的内部实现方式是什么?

ASP. Net core introduction I
随机推荐
Distributed base theory
SQL language
How to choose a technology stack for web applications in 2022
Dgraph: large scale dynamic graph dataset
MySQL5免安装修改
C#基础深入学习一
C语言中学生成绩管理系统
免费、好用、强大的轻量级笔记软件评测:Drafts、Apple 备忘录、Flomo、Keep、FlowUs、Agenda、SideNote、Workflowy
担心“断气” 德国正修改《能源安全法》
MySQL8版本免安装步骤教程
. Net using redis
Redis —— How To Install Redis And Configuration(如何快速在 Ubuntu18.04 与 CentOS7.6 Linux 系统上安装 Redis)
1200. 最小绝对差
The old-fashioned synchronized lock optimization will make it clear to you at once!
XILINX/system-controller-c/BoardUI/无法连接开发板,任意操作后卡死的解决办法
. Net delay queue
2022年山东省安全员C证考试题库及在线模拟考试
面试拆解:系统上线后Cpu使用率飙升如何排查?
C array supplement
C basic supplement