当前位置:网站首页>【C 语言】 题集 of Ⅹ
【C 语言】 题集 of Ⅹ
2022-07-07 14:13:00 【InfoQ】
write in front
第四十六题→创建自定义函数,从而实现strcat()的功能
char *strcat(char *dest, const char *src)
第四十七题→求 1! + 2! + 3! ... +n!;不考虑溢出
第四十八题→创建自定义函数,实现字符串函数strcpy()
char *strcpy(char *dest, const char *src)
第四十九题→计算在n的参数当中的补码有多少二进制当中的1
第五十零题→设计一个算法,求输入A和B的最小公倍数
第四十六题の代码
#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'的ASCLL码值就是0
{
dest++;
}
//dest指向的是'\0'
while (*dest++ = *src++)
{
;
}
/*相当于
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;
}
第四十七题の代码
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int main(void)
{
//代入法 1*1 + 1*2 + 1*2*3 + 1*2*3*4 - 假设输入数字:4
int i = 0;
int j = 0;
int num = 0;
int sum = 0;
printf("请输入数字->:");
scanf("%d", &num);
for (i = 1; i <= num; i++)
{
int ret = 1;//注意->ret
for (j = 1; j <= i; j++)
{
ret = j * ret;//每一次阶层之和
}
sum = ret + sum;//总和
}
printf("sum = %d\n", sum);
return 0;
}
第四十八题の代码
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <assert.h>
void my_strcpy(char* str1, char* str2)
{
assert(str1 && str2 != NULL);//断言!
//把字符串str2赋值给str1,遇到'\0'结束。
while (*str2 != '\0')
{
*str1++ = *str2++;
}
}
int main(void)
{
char str[20] = { 0 };
char p[20] = { 0 };
printf("请输入字符串->:");
scanf("%s", str);
my_strcpy(p, str);
printf("ret = %s\n",p);
return 0;
}
第四十九题の代码
#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++)
{
// 假设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("请输入数字:");
scanf("%d", &n);
int ret = function(n);
printf("ret = %d\n", ret);
return 0;
}
第五十零题の代码
#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("请输入两个数字->:");
scanf("%d %d", &a, &b);
while (i)
{
if (a*i % b == 0)
{
printf("最小公倍数:%d\n", a*i);
break;
}
i++;//注意→i++的位置
}
return 0;
}
边栏推荐
- Apache Doris刚“毕业”:为什么应关注这种SQL数据仓库?
- Unity3D_ Class fishing project, control the distance between collision walls to adapt to different models
- Numpy --- basic learning notes
- torch.numel作用
- 47_ Contour lookup in opencv cv:: findcontours()
- Three. JS introductory learning notes 13: animation learning
- Asyncio concept and usage
- Dotween -- ease function
- Unity3d click events added to 3D objects in the scene
- Three. Introduction to JS learning notes 17: mouse control of 3D model rotation of JSON file
猜你喜欢
Rongyun won the 2022 China Xinchuang digital office portal excellence product award!
分步式監控平臺zabbix
Three. JS introductory learning notes 15: threejs frame animation module
分步式监控平台zabbix
Numpy -- epidemic data analysis case
Multiplication in pytorch: mul (), multiply (), matmul (), mm (), MV (), dot ()
torch. Numel action
神经网络c语言中的指针是怎么回事
喜讯!科蓝SUNDB数据库与鸿数科技隐私数据保护管理软件完成兼容性适配
Vs tool word highlight with margin
随机推荐
How does geojson data merge the boundaries of regions?
Shipping companies' AI products are mature, standardized and applied on a large scale. CIMC, the global leader in port and shipping AI / container AI, has built a benchmark for international shipping
pycharm 终端部启用虚拟环境
What are compiled languages and interpreted languages?
Wireless sensor networks -- ZigBee and 6LoWPAN
融云斩获 2022 中国信创数字化办公门户卓越产品奖!
How to query the data of a certain day, a certain month, and a certain year in MySQL
JS modularization
Eye of depth (VII) -- Elementary Transformation of matrix (attachment: explanation of some mathematical models)
Laravel5.1 路由 -路由分组
Migration and reprint
The inevitable trend of the intelligent development of ankerui power grid is that microcomputer protection devices are used in power systems
Three. JS introductory learning notes 19: how to import FBX static model
You Yuxi, coming!
PHP实现微信小程序人脸识别刷脸登录功能
Bidding announcement: Fujian Rural Credit Union database audit system procurement project (re bidding)
Talk about the cloud deployment of local projects created by SAP IRPA studio
The unity vector rotates at a point
Numpy --- basic learning notes
Lecturer solicitation order | Apache seatunnel (cultivating) meetup sharing guests are in hot Recruitment!