当前位置:网站首页>[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
边栏推荐
猜你喜欢
Install Trinity and solve error reporting
One of the solutions for unity not recognizing riders
Summary of recent days (non-technical article)
Automatic filling of database public fields
逆向调试入门-PE结构-资源表07/07
30: Chapter 3: develop Passport Service: 13: develop [change / improve user information, interface]; (use * * * Bo class to accept parameters, and use parameter verification)
The only core indicator of high-quality software architecture
205. 同构字符串
德明利深交所上市:市值31亿 为李虎与田华夫妻档
数据库公共字段自动填充
随机推荐
JVM系列——栈与堆、方法区day1-2
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
ViewBinding和DataBinding的理解和区别
unity不识别rider的其中一种解决方法
美国土安全部长:国内暴力极端主义是目前美面临的最大恐怖主义威胁之一
OPPO Find N2产品形态首曝:补齐各项短板
2022 hoisting machinery command examination simulation 100 questions simulation examination platform operation
Introduction to XML I
Detailed explanation of Fisher information quantity detection countermeasure sample code
find命令报错: paths must precede expression(转)
The Secretary of Homeland Security warned immigrants "not to embark on a dangerous journey"
Lick the dog until the last one has nothing (state machine)
392. 判断子序列
Node の MongoDB安装
中邮科技冲刺科创板:年营收20.58亿 邮政集团是大股东
Interview disassembly: how to check the soaring usage of CPU after the system goes online?
C language Dormitory Management Query Software
MySQL 45 lecture - learn the actual combat notes of MySQL in Geek time 45 lecture - 06 | global lock and table lock_ Why are there so many obstacles in adding a field to the table
Redis —— How To Install Redis And Configuration(如何快速在 Ubuntu18.04 与 CentOS7.6 Linux 系统上安装 Redis)
FS7867S是一款应用于数字系统供电电源电压监控的电压检测芯片