当前位置:网站首页>【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;
}
边栏推荐
- Use moviepy Editor clips videos and intercepts video clips in batches
- 喜讯!科蓝SUNDB数据库与鸿数科技隐私数据保护管理软件完成兼容性适配
- Tragedy caused by deleting the console statement
- The differences between exit, exit (0), exit (1), exit ('0 '), exit ('1'), die and return in PHP
- iptables只允许指定ip地址访问指定端口
- 企业级日志分析系统ELK
- 深度之眼(六)——矩阵的逆(附:logistic模型一些想法)
- thinkphp3.2.3中设置路由,优化url
- Numpy --- basic learning notes
- TiDB For PostgreSQL和YugabyteDB在Sysbench上的性能对比
猜你喜欢
Excessive dependence on subsidies, difficult collection of key customers, and how strong is the potential to reach the dream of "the first share of domestic databases"?
Logback日志框架第三方jar包 免费获取
Xcode Revoke certificate
Multiplication in pytorch: mul (), multiply (), matmul (), mm (), MV (), dot ()
Application example of infinite list [uigridview]
Odoo integrated plausible embedded code monitoring platform
航運船公司人工智能AI產品成熟化標准化規模應用,全球港航人工智能/集裝箱人工智能領軍者CIMC中集飛瞳,打造國際航運智能化標杆
Performance comparison of tidb for PostgreSQL and yugabytedb on sysbench
AE learning 01: AE complete project summary
PyTorch 中的乘法:mul()、multiply()、matmul()、mm()、mv()、dot()
随机推荐
喜讯!科蓝SUNDB数据库与鸿数科技隐私数据保护管理软件完成兼容性适配
A JS script can be directly put into the browser to perform operations
How does laravel run composer dump autoload without emptying the classmap mapping relationship?
hellogolang
laravel 是怎么做到运行 composer dump-autoload 不清空 classmap 映射关系的呢?
Markdown formula editing tutorial
【花雕体验】15 尝试搭建Beetle ESP32 C3之Arduino开发环境
AE learning 02: timeline
Three. JS introductory learning notes 19: how to import FBX static model
Is it reliable to open an account on Tongda letter with your mobile phone? Is there any potential safety hazard in such stock speculation
Bidding announcement: 2022 Yunnan Unicom gbase database maintenance public comparison and selection project (second) comparison and selection announcement
Apache Doris just "graduated": why should we pay attention to this kind of SQL data warehouse?
C4D learning notes 2- animation - timeline and time function
Odoo integrated plausible embedded code monitoring platform
Leetcode-136- number that appears only once (solve with XOR)
Iptables only allows the specified IP address to access the specified port
Continuous creation depends on it!
目标跟踪常见训练数据集格式
Good news! Kelan sundb database and Hongshu technology privacy data protection management software complete compatibility adaptation
星瑞格数据库入围“2021年度福建省信息技术应用创新典型解决方案”