当前位置:网站首页>[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;
}
边栏推荐
- 47_ Contour lookup in opencv cv:: findcontours()
- Odoo集成Plausible埋码监控平台
- JS 模块化
- Laravel post shows an exception when submitting data
- leetcode 241. Different ways to add parentheses design priority for operational expressions (medium)
- [summary of knowledge] summary of notes on using SVN in PHP
- Laravel changed the session from file saving to database saving
- PHP realizes wechat applet face recognition and face brushing login function
- Limit of total fields [1000] in index has been exceeded
- Logback logging framework third-party jar package is available for free
猜你喜欢
删除 console 语句引发的惨案
Power of leetcode-231-2
深度之眼(七)——矩阵的初等变换(附:数模一些模型的解释)
Mysql database basic operation DQL basic query
如何快速检查钢网开口面积比是否符合 IPC7525
Multiplication in pytorch: mul (), multiply (), matmul (), mm (), MV (), dot ()
[Android -- data storage] use SQLite to store data
【C 语言】 题集 of Ⅹ
Odoo integrated plausible embedded code monitoring platform
Sysom case analysis: where is the missing memory| Dragon lizard Technology
随机推荐
torch.numel作用
星瑞格数据库入围“2021年度福建省信息技术应用创新典型解决方案”
Description of vs common shortcut keys
Is it reliable to open an account on Tongda letter with your mobile phone? Is there any potential safety hazard in such stock speculation
无法将“pip”项识别为 cmdlet、函数、脚本文件或可运行程序的名称
hellogolang
Enterprise log analysis system elk
【C 语言】 题集 of Ⅹ
The inevitable trend of the intelligent development of ankerui power grid is that microcomputer protection devices are used in power systems
Three singleton modes of unity (hungry man, lazy man, monobehavior)
[flower carving experience] 15 try to build the Arduino development environment of beetle esp32 C3
prometheus api删除某个指定job的所有数据
Odoo集成Plausible埋码监控平台
23. 合并K个升序链表-c语言
js中复选框checkbox如何判定为被选中
Common training data set formats for target tracking
TiDB For PostgreSQL和YugabyteDB在Sysbench上的性能对比
The differences between exit, exit (0), exit (1), exit ('0 '), exit ('1'), die and return in PHP
laravel构造函数和中间件执行顺序问题
Laravel changed the session from file saving to database saving