当前位置:网站首页>[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
边栏推荐
- C language programming topic reference
- CA: efficient coordinate attention mechanism for mobile terminals | CVPR 2021
- 苹果5G芯片研发失败:继续依赖高通,还要担心被起诉?
- Introduction to XML III
- 舔狗舔到最后一无所有(状态机)
- MySQL5免安装修改
- 易周金融 | Q1保险行业活跃人数8688.67万人 19家支付机构牌照被注销
- XML入门一
- Understanding and difference between viewbinding and databinding
- Web知识补充
猜你喜欢

unity不识别rider的其中一种解决方法

30:第三章:开发通行证服务:13:开发【更改/完善用户信息,接口】;(使用***BO类承接参数,并使用了参数校验)

2022危险化学品经营单位主要负责人练习题及模拟考试

392. 判断子序列

2022年山东省安全员C证考试题库及在线模拟考试

Source code compilation and installation of MySQL

Commvault 和 Oracle 合作,在 Oracle 云上提供 Metallic数据管理即服务

Understanding and difference between viewbinding and databinding

Openharmony application development how to create dayu200 previewer

Redis —— How To Install Redis And Configuration(如何快速在 Ubuntu18.04 与 CentOS7.6 Linux 系统上安装 Redis)
随机推荐
Haproxy high availability solution
Variable promotion and function promotion in JS
美国土安全部部长警告移民“不要踏上危险的旅程”
高质量软件架构的唯一核心指标
JVM series - stack and heap, method area day1-2
The only core indicator of high-quality software architecture
#yyds干货盘点# 解决名企真题:连续最大和
js中的变量提升和函数提升
2022危险化学品经营单位主要负责人练习题及模拟考试
【Antd踩坑】Antd Form 配合Input.Group时出现Form.Item所占据的高度不对
提高MySQL深分页查询效率的三种方案
華昊中天沖刺科創板:年虧2.8億擬募資15億 貝達藥業是股東
Web知识补充
C language programming topic reference
Optional values and functions of the itemized contenttype parameter in the request header
Scrapy 框架学习
SQL language
Openharmony application development how to create dayu200 previewer
2022年起重机械指挥考试模拟100题模拟考试平台操作
Using nsproxy to forward messages