当前位置:网站首页>【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;
}
最后
边栏推荐
- 美国土安全部部长警告移民“不要踏上危险的旅程”
- FS7867S是一款应用于数字系统供电电源电压监控的电压检测芯片
- 读取 Excel 表数据
- 2022G3锅炉水处理考试题模拟考试题库及模拟考试
- 微服务入门
- SQL language
- 2022 hoisting machinery command examination simulation 100 questions simulation examination platform operation
- 硬件基础知识-二极管基础
- Five "potential errors" in embedded programming
- Cors: standard scheme of cross domain resource request
猜你喜欢
面试拆解:系统上线后Cpu使用率飙升如何排查?
锐成芯微冲刺科创板:年营收3.67亿拟募资13亿 大唐电信是股东
Getting started with the go language is simple: go implements the Caesar password
unity不识别rider的其中一种解决方法
Dgraph: large scale dynamic graph dataset
Interviewer: what is the internal implementation of hash data type in redis?
One of the solutions for unity not recognizing riders
使用默认路由作为指向Internet的路由
Understanding and difference between viewbinding and databinding
字节面试算法题
随机推荐
C language Dormitory Management Query Software
Oracle was named the champion of Digital Innovation Award by Ventana research
392. 判断子序列
Using scrcpy projection
Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
如何在 2022 年为 Web 应用程序选择技术堆栈
Scrapy 框架学习
博士申请 | 西湖大学学习与推理系统实验室招收博后/博士/研究实习等
Oracle 被 Ventana Research 评为数字创新奖总冠军
Fs4056 800mA charging IC domestic fast charging power IC
2022危险化学品经营单位主要负责人练习题及模拟考试
Cors: standard scheme of cross domain resource request
C语言职工管理系统
数据库公共字段自动填充
源码编译安装MySQL
德明利深交所上市:市值31亿 为李虎与田华夫妻档
近日小结(非技术文)
Introduction to XML II
CommVault cooperates with Oracle to provide metallic data management as a service on Oracle cloud
When MDK uses precompiler in header file, ifdef is invalid