当前位置:网站首页>[C question set] of VII
[C question set] of VII
2022-07-04 14:00:00 【InfoQ】
write in front
Question 31 → Simulation Implementation strcat() function
char *strcat(char *dest, const char *src)
Question 32 → Enter ten numbers randomly , The numbers are arranged from large to small
Question 33 → Use a function to create a variable inside the function to exchange variables with two values
Question 34 → Receive an integer value ( Unsigned form ), Print out each bit in order . for example :1234, Output 1 2 3 4( Recursive form )
- There are restrictions , When this restriction is met , Recursion will not continue .
- After each recursive call, it gets closer and closer to this limit .
Question 35 → Simulate the print length of string function , In the form of recursion , Cannot create temporary variable
size_t strlen ( const char * str );
Question 31 → Code
#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' Of ASCLL The code value is 0
{
dest++;
}
//dest Pointing to '\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;
}
Question 32 → Code
#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(" Please enter a number :");
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]);
}
// Compare adjacent elements . If the first one is bigger than the second one , Just swap them .
// Each trip starts with the first pair of adjacent elements , Do the same for each pair of adjacent elements , Until the last pair .
// Repeat the above steps for all elements , Except for sorted elements ( The last element after each sort ), Until there's no pair of numbers to compare
return 0;
}
Question 33 → Code
#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(" Before the exchange :a=%d,b=%d\n", a, b);
swap(&a, &b);
printf("------------------\n");
printf(" After the exchange :a=%d,b=%d\n", a, b);
return 0;
}
Question 34 → Code
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
void print(unsigned int number)
{
if (number > 9) // Limiting conditions
{
print(number / 10); // Call this function , Until the expression is false, execute the following statement ,1234 123 12 1
}
printf("%d ", number % 10);
}
int main(void)
{
unsigned int number = 0;
printf(" Please enter a number :");
scanf("%u", &number);
print(number);
return 0;
}
Question 35 → Code
#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(" Please enter the characters :");
scanf("%s", &arr);
printf("str = %d\n", My_strlen(arr));
return 0;
}
Last
边栏推荐
猜你喜欢
【Antd】Antd 如何在 Form.Item 中有 Input.Gourp 时获取 Input.Gourp 的每一个 Input 的value
MySQL45讲——学习极客时间MySQL实战45讲笔记—— 06 | 全局锁和表锁_给表加个字段怎么有这么多阻碍
When MDK uses precompiler in header file, ifdef is invalid
Database lock table? Don't panic, this article teaches you how to solve it
硬件基础知识-二极管基础
CVPR 2022 | 大幅减少零样本学习所需的人工标注,提出富含视觉信息的类别语义嵌入(源代码下载)...
Oracle 被 Ventana Research 评为数字创新奖总冠军
华昊中天冲刺科创板:年亏2.8亿拟募资15亿 贝达药业是股东
Fisher信息量检测对抗样本代码详解
2022年起重机械指挥考试模拟100题模拟考试平台操作
随机推荐
js中的变量提升和函数提升
The Secretary of Homeland Security warned immigrants "not to embark on a dangerous journey"
C语言程序设计
【Antd踩坑】Antd Form 配合Input.Group时出现Form.Item所占据的高度不对
ViewBinding和DataBinding的理解和区别
一次 Keepalived 高可用的事故,让我重学了一遍它
源码编译安装MySQL
Oracle 被 Ventana Research 评为数字创新奖总冠军
MySQL5免安装修改
Distributed base theory
Animation and transition effects
忠诚协议是否具有法律效力
C#基础深入学习二
Fs4056 800mA charging IC domestic fast charging power IC
Three schemes to improve the efficiency of MySQL deep paging query
ASP. Net core introduction I
【R语言数据科学】:交叉验证再回首
7 月数据库排行榜:MongoDB 和 Oracle 分数下降最多
Getting started with microservices
C语言课程设计题