当前位置:网站首页>【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;
}
最后
边栏推荐
- Variable promotion and function promotion in JS
- C语言程序设计
- 30:第三章:开发通行证服务:13:开发【更改/完善用户信息,接口】;(使用***BO类承接参数,并使用了参数校验)
- The only core indicator of high-quality software architecture
- Cors: standard scheme of cross domain resource request
- C语言课程设计题
- C语言职工管理系统
- Interview disassembly: how to check the soaring usage of CPU after the system goes online?
- Samsung's mass production of 3nm products has attracted the attention of Taiwan media: whether it can improve the input-output rate in the short term is the key to compete with TSMC
- AI painting minimalist tutorial
猜你喜欢
2022kdd pre lecture | 11 first-class scholars take you to unlock excellent papers in advance
CVPR 2022 | 大幅减少零样本学习所需的人工标注,提出富含视觉信息的类别语义嵌入(源代码下载)...
Oracle was named the champion of Digital Innovation Award by Ventana research
One of the solutions for unity not recognizing riders
7 月数据库排行榜:MongoDB 和 Oracle 分数下降最多
Commvault 和 Oracle 合作,在 Oracle 云上提供 Metallic数据管理即服务
Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation
数据库公共字段自动填充
MySQL5免安装修改
嵌入式编程中五个必探的“潜在错误”
随机推荐
Getting started with the go language is simple: go implements the Caesar password
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
Install Trinity and solve error reporting
392. 判断子序列
CommVault cooperates with Oracle to provide metallic data management as a service on Oracle cloud
苹果5G芯片研发失败:继续依赖高通,还要担心被起诉?
英视睿达冲刺科创板:年营收4.5亿 拟募资9.79亿
C语言小型商品管理系统
Openharmony application development how to create dayu200 previewer
Introduction to reverse debugging PE structure resource table 07/07
Source code compilation and installation of MySQL
安装trinity、解决报错
The only core indicator of high-quality software architecture
Node mongodb installation
C语言宿舍管理查询软件
读取 Excel 表数据
Byte interview algorithm question
XML入门三
Using nsproxy to forward messages
XML入门二