当前位置:网站首页>[C language] question set of X
[C language] question set of X
2022-07-07 16:28:00 【InfoQ】
write in front
Question 46 → Create a custom function , So as to achieve strcat() The function of
char *strcat(char *dest, const char *src)
Question 47 → seek 1! + 2! + 3! ... +n!; Don't think about spillovers
Question 48 → Create a custom function , Implement string functions strcpy()
char *strcpy(char *dest, const char *src)
Question 49 → Calculated at n How many binary complements are there in the parameters of 1
Question 50 → Design an algorithm , Find input A and B The least common multiple of

Question 46 の 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);// Assertion
char *ret = dest;
while (*dest != '\0')//'\0' Of ASCLL The code value is 0
{
dest++;
}
//dest Pointing to '\0'
while (*dest++ = *src++)
{
;
}
/* amount to
while (*src != '\0')
{
*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 47 の Code
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int main(void)
{
// Substitution method 1*1 + 1*2 + 1*2*3 + 1*2*3*4 - Suppose you enter a number :4
int i = 0;
int j = 0;
int num = 0;
int sum = 0;
printf(" Please enter a number ->:");
scanf("%d", &num);
for (i = 1; i <= num; i++)
{
int ret = 1;// Be careful ->ret
for (j = 1; j <= i; j++)
{
ret = j * ret;// The sum of each class
}
sum = ret + sum;// The sum of the
}
printf("sum = %d\n", sum);
return 0;
}
Question 48 の Code
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <assert.h>
void my_strcpy(char* str1, char* str2)
{
assert(str1 && str2 != NULL);// Assertion !
// Put the string str2 Assign a value to str1, encounter '\0' end .
while (*str2 != '\0')
{
*str1++ = *str2++;
}
}
int main(void)
{
char str[20] = { 0 };
char p[20] = { 0 };
printf(" Please enter the string ->:");
scanf("%s", str);
my_strcpy(p, str);
printf("ret = %s\n",p);
return 0;
}
Question 49 の Code
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int function(int n)
{
int count = 0;
int i = 0;
for (i = 0; i < 32; i++)
{
// hypothesis n = 3
// 0011 >> 0 - 0011 & 1111 +1
// 0011 >> 1 - 0001 & 1111 +2
// 0001 >> 2 - 0000 & 1111 count = 2
if (((n >> i) & 1) == 1)
{
count++;
}
}
return count;
}
int main(void)
{
int n = 0;
printf(" Please enter a number :");
scanf("%d", &n);
int ret = function(n);
printf("ret = %d\n", ret);
return 0;
}
Question 50 の Code
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
typedef unsigned long int u_lint;
int main(void)
{
int i = 1;
u_lint a = 0;
u_lint b = 0;
printf(" Please enter two numbers ->:");
scanf("%d %d", &a, &b);
while (i)
{
if (a*i % b == 0)
{
printf(" Minimum common multiple :%d\n", a*i);
break;
}
i++;// Be careful →i++ The location of
}
return 0;
}
边栏推荐
- php 自带过滤和转义函数
- Rongyun won the 2022 China Xinchuang digital office portal excellence product award!
- Application example of infinite list [uigridview]
- Performance measure of classification model
- Power of leetcode-231-2
- ThinkPHP URL 路由简介
- 面试题 01.02. 判定是否互为字符重排-辅助数组算法
- SPI master RX time out interrupt
- Markdown formula editing tutorial
- 记一次项目的迁移过程
猜你喜欢
Xingruige database was shortlisted as the "typical solution for information technology application and innovation in Fujian Province in 2021"
Step by step monitoring platform ZABBIX
Logback logging framework third-party jar package is available for free
Xcode Revoke certificate
华东师大团队提出,具有DNA调控电路的卷积神经网络的系统分子实现
深度之眼(六)——矩阵的逆(附:logistic模型一些想法)
Application example of infinite list [uigridview]
记录Servlet学习时的一次乱码
Unity3d click events added to 3D objects in the scene
PyTorch 中的乘法:mul()、multiply()、matmul()、mm()、mv()、dot()
随机推荐
leetcode 241. Different ways to add parentheses design priority for operational expressions (medium)
Xcode Revoke certificate
Introduction to pyGame games
Common training data set formats for target tracking
prometheus api删除某个指定job的所有数据
一个普通人除了去工厂上班赚钱,还能干什么工作?
Laravel5.1 路由 -路由分组
thinkphp3.2.3中设置路由,优化url
Shader basic UV operations, translation, rotation, scaling
IP地址和物理地址有什么区别
How to implement backspace in shell
Mysql database basic operation DQL basic query
Balanced binary tree (AVL)
PHP realizes wechat applet face recognition and face brushing login function
JS中null NaN undefined这三个值有什么区别
Logback日志框架第三方jar包 免费获取
Xcode Revoke certificate
谈谈 SAP iRPA Studio 创建的本地项目的云端部署问题
Bidding announcement: Panjin people's Hospital Panjin hospital database maintenance project
Statistical learning method -- perceptron