当前位置:网站首页>【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;
}
边栏推荐
- 喜讯!科蓝SUNDB数据库与鸿数科技隐私数据保护管理软件完成兼容性适配
- 95.(cesium篇)cesium动态单体化-3D建筑物(楼栋)
- Odoo integrated plausible embedded code monitoring platform
- asyncio 概念和用法
- Sysom case analysis: where is the missing memory| Dragon lizard Technology
- Balanced binary tree (AVL)
- Laravel5.1 路由 -路由分组
- leetcode 241. Different Ways to Add Parentheses 为运算表达式设计优先级(中等)
- 深度之眼(六)——矩阵的逆(附:logistic模型一些想法)
- pycharm 终端部启用虚拟环境
猜你喜欢
TiDB For PostgreSQL和YugabyteDB在Sysbench上的性能对比
通知Notification使用全解析
Statistical learning method -- perceptron
Three. JS introductory learning notes 15: threejs frame animation module
过度依赖补助,大客户收款难,冲刺“国产数据库第一股”的达梦后劲有多足?
分步式监控平台zabbix
C4D learning notes 1- animation - animation key frames
SPI master rx time out中断
Wireless sensor networks -- ZigBee and 6LoWPAN
Logback logging framework third-party jar package is available for free
随机推荐
laravel中将session由文件保存改为数据库保存
目标跟踪常见训练数据集格式
Laravel5.1 路由 -路由分组
Unity3d click events added to 3D objects in the scene
Three singleton modes of unity (hungry man, lazy man, monobehavior)
C4D learning notes 3- animation - animation rendering process case
TCP framework___ Unity
Three. JS introductory learning notes 15: threejs frame animation module
Unity3D_ Class fishing project, control the distance between collision walls to adapt to different models
Vs tool word highlight with margin
PHP实现执行定时任务的几种思路详解
torch. Numel action
Description of vs common shortcut keys
应用程序和matlab的通信方式
Bidding announcement: 2022 Yunnan Unicom gbase database maintenance public comparison and selection project (second) comparison and selection announcement
95.(cesium篇)cesium动态单体化-3D建筑物(楼栋)
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
IP地址和物理地址有什么区别
What about the pointer in neural network C language
JS 模块化