当前位置:网站首页>[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 basic supplement
- Lick the dog until the last one has nothing (state machine)
- 德明利深交所上市:市值31亿 为李虎与田华夫妻档
- Web知识补充
- Go 语言入门很简单:Go 实现凯撒密码
- After the game starts, you will be prompted to install HMS core. Click Cancel, and you will not be prompted to install HMS core again (initialization failure returns 907135003)
- remount of the / superblock failed: Permission denied
- The only core indicator of high-quality software architecture
- C language Dormitory Management Query Software
- Fisher信息量检测对抗样本代码详解
猜你喜欢
英视睿达冲刺科创板:年营收4.5亿 拟募资9.79亿
Dgraph: large scale dynamic graph dataset
205. 同构字符串
数据库公共字段自动填充
基于STM32+华为云IOT设计的酒驾监控系统
392. 判断子序列
ASP.NET Core入门一
ASP. Net core introduction I
Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation
One of the solutions for unity not recognizing riders
随机推荐
2022KDD预讲 | 11位一作学者带你提前解锁优秀论文
2022危险化学品经营单位主要负责人练习题及模拟考试
C language staff management system
Scrapy 框架学习
Doctoral application | West Lake University Learning and reasoning system laboratory recruits postdoctoral / doctoral / research internship, etc
Three schemes to improve the efficiency of MySQL deep paging query
硬件基础知识-二极管基础
DGraph: 大规模动态图数据集
c#数组补充
Dgraph: large scale dynamic graph dataset
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
XML入门二
Using scrcpy projection
Flet教程之 03 FilledButton基础入门(教程含源码)(教程含源码)
2022G3锅炉水处理考试题模拟考试题库及模拟考试
基于链表管理的单片机轮询程序框架
嵌入式编程中五个必探的“潜在错误”
OPPO Find N2产品形态首曝:补齐各项短板
SQL语言
CA: efficient coordinate attention mechanism for mobile terminals | CVPR 2021