当前位置:网站首页>[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
边栏推荐
- Introduction to XML II
- C语言职工管理系统
- 【Antd】Antd 如何在 Form.Item 中有 Input.Gourp 时获取 Input.Gourp 的每一个 Input 的value
- C语言集合运算
- Fisher信息量检测对抗样本代码详解
- Oracle was named the champion of Digital Innovation Award by Ventana research
- Haproxy high availability solution
- How to choose a technology stack for web applications in 2022
- 面试官:Redis中哈希数据类型的内部实现方式是什么?
- ASP.NET Core入门一
猜你喜欢
上汽大通MAXUS正式发布全新品牌“MIFA”,旗舰产品MIFA 9正式亮相!
1200. 最小绝对差
Haproxy high availability solution
2022g3 boiler water treatment examination question simulation examination question bank and simulation examination
CVPR 2022 | 大幅减少零样本学习所需的人工标注,提出富含视觉信息的类别语义嵌入(源代码下载)...
英视睿达冲刺科创板:年营收4.5亿 拟募资9.79亿
如何在 2022 年为 Web 应用程序选择技术堆栈
30:第三章:开发通行证服务:13:开发【更改/完善用户信息,接口】;(使用***BO类承接参数,并使用了参数校验)
2022 Shandong Province safety officer C certificate examination question bank and online simulation examination
安装trinity、解决报错
随机推荐
C语言个人通讯录管理系统
SCM polling program framework based on linked list management
C array supplement
C语言程序设计
Getting started with microservices
C语言中学生成绩管理系统
微服务入门
C foundation in-depth study I
ViewBinding和DataBinding的理解和区别
In 2022, it will be es2022 soon. Do you only know the new features of ES6?
上汽大通MAXUS正式发布全新品牌“MIFA”,旗舰产品MIFA 9正式亮相!
硬件基础知识-二极管基础
嵌入式编程中五个必探的“潜在错误”
Redis - how to install redis and configuration (how to quickly install redis on ubuntu18.04 and centos7.6 Linux systems)
忠诚协议是否具有法律效力
逆向调试入门-PE结构-资源表07/07
2022g3 boiler water treatment examination question simulation examination question bank and simulation examination
. Net delay queue
js中的变量提升和函数提升
Redis —— How To Install Redis And Configuration(如何快速在 Ubuntu18.04 与 CentOS7.6 Linux 系统上安装 Redis)