当前位置:网站首页>[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;
}
边栏推荐
- iptables只允许指定ip地址访问指定端口
- pycharm 终端部启用虚拟环境
- 【C 语言】 题集 of Ⅹ
- 分类模型评价标准(performance measure)
- Lecturer solicitation order | Apache seatunnel (cultivating) meetup sharing guests are in hot Recruitment!
- Xcode Revoke certificate
- Balanced binary tree (AVL)
- Laravel 中config的用法
- 华东师大团队提出,具有DNA调控电路的卷积神经网络的系统分子实现
- Dotween -- ease function
猜你喜欢
Talk about the cloud deployment of local projects created by SAP IRPA studio
Performance comparison of tidb for PostgreSQL and yugabytedb on sysbench
Rongyun won the 2022 China Xinchuang digital office portal excellence product award!
The unity vector rotates at a point
pycharm 终端部启用虚拟环境
Logback日志框架第三方jar包 免费获取
Plate - forme de surveillance par étapes zabbix
Application example of infinite list [uigridview]
深度之眼(六)——矩阵的逆(附:logistic模型一些想法)
spark调优(三):持久化减少二次查询
随机推荐
目标跟踪常见训练数据集格式
Communication mode between application program and MATLAB
PyTorch 中的乘法:mul()、multiply()、matmul()、mm()、mv()、dot()
PHP realizes wechat applet face recognition and face brushing login function
Good news! Kelan sundb database and Hongshu technology privacy data protection management software complete compatibility adaptation
企业级日志分析系统ELK
TiDB For PostgreSQL和YugabyteDB在Sysbench上的性能对比
Laravel post shows an exception when submitting data
面试题 01.02. 判定是否互为字符重排-辅助数组算法
统计学习方法——感知机
Logback日志框架第三方jar包 免费获取
预测——灰色预测
[flower carving experience] 15 try to build the Arduino development environment of beetle esp32 C3
Shandong old age Expo, 2022 China smart elderly care exhibition, smart elderly care and aging technology exhibition
Xcode Revoke certificate
Common training data set formats for target tracking
What about the pointer in neural network C language
Application example of infinite list [uigridview]
Asyncio concept and usage
Statistical learning method -- perceptron