当前位置:网站首页>[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
边栏推荐
- 英视睿达冲刺科创板:年营收4.5亿 拟募资9.79亿
- E-week finance | Q1 the number of active people in the insurance industry was 86.8867 million, and the licenses of 19 Payment institutions were cancelled
- C语言图书租赁管理系统
- 高质量软件架构的唯一核心指标
- MySQL5免安装修改
- Using nsproxy to forward messages
- 2022KDD预讲 | 11位一作学者带你提前解锁优秀论文
- Byte interview algorithm question
- Go 语言入门很简单:Go 实现凯撒密码
- Don't turn down, three sentences to clarify the origin of cross domain resource request errors
猜你喜欢
2022年山东省安全员C证考试题库及在线模拟考试
CommVault cooperates with Oracle to provide metallic data management as a service on Oracle cloud
OpenHarmony应用开发之如何创建DAYU200预览器
提高MySQL深分页查询效率的三种方案
动画与过渡效果
Go 语言入门很简单:Go 实现凯撒密码
源码编译安装MySQL
Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation
ASP.NET Core入门一
unity不识别rider的其中一种解决方法
随机推荐
ViewBinding和DataBinding的理解和区别
读取 Excel 表数据
美国土安全部部长警告移民“不要踏上危险的旅程”
MongoDB常用28条查询语句(转)
CTF competition problem solution STM32 reverse introduction
Introduction to XML II
The only core indicator of high-quality software architecture
OpenHarmony应用开发之如何创建DAYU200预览器
Node の MongoDB 安装
C语言小型商品管理系统
Introduction to XML I
2022KDD预讲 | 11位一作学者带你提前解锁优秀论文
美国土安全部长:国内暴力极端主义是目前美面临的最大恐怖主义威胁之一
C language Dormitory Management Query Software
Using scrcpy projection
XILINX/system-controller-c/BoardUI/无法连接开发板,任意操作后卡死的解决办法
Install Trinity and solve error reporting
逆向调试入门-PE结构-资源表07/07
.Net之延迟队列
Using nsproxy to forward messages