当前位置:网站首页>【C 题集】of Ⅷ
【C 题集】of Ⅷ
2022-07-05 14:33:00 【InfoQ】
write in front
第三十六题→求斐波那契数!输入数字求对应的斐波那契数列
第三十七题→计算1到100的数,求个位上的数字9和十位上的数字9给打印出来,并且用Count计算打印出来数字的总和
第三十八题→分别计算 1/1+1+2/1+3/1+4/1+5/+......+1/99+1/100 和 1/1-1/2-1/3-1/4-1-5-......-1/99-1/100 的值
第三十九题→模拟实现字符串函数,任意输入~求字符串函数长度
size_t strlen ( const char * str );第四十题零→任意输入字符串实现逆序打印,不能使用C自带的字符串库函数
第三十六题→代码
#include<stdio.h>
//斐波那契数列:前两个数之和等于第三个数字
/* 1 1 2 3 5 8 13 21 34
a b c
1 2 3 4 5 6 7 8 9*/
int Fib(int n)
{
int a = 1;
int b = 1;
int c = 1;
while (n > 2)//只要求第2个以后的斐波那契数就执行while循环
{
c = a + b;
a = b;
b = c;
n--;//n = n - 1;每次执行一次就减一直到n=2为止。
}
return c;
}
int main(void)
{
int n = 0;
int let = 0;
printf("请输入数字:");
scanf_s("%d", &n);
ret = Fib(n);
printf("ret = %d\n", ret);
return 0;
}#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int fib(int n) {
if (n==1 || n==2) {
return 1;
}
return fib(n - 1) + fib(n - 2);
}
int main()
{
int n = 0;
printf("请输入要求第几个数字:");
scanf("%d", &n);
printf("%d\n", fib(n));
return 0;
}
第三十七题→代码
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main(void)
{
int i = 0;
int Count = 0;
for (i = 0; i < 101; i++)
{
//个位
if (i % 10 == 9)
{
printf("%d ", i);
Count++;
}
//十位
if (i / 10 == 9)
{
printf("%d ", i);
Count++;
}
}
printf("\nCount=%d\n", Count);
return 0;
}
第三十八题→代码
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main(void)
{
int i = 1;
double sum1 = 0;
double sum2 = 0;
for (i = 1; i < 100; i++)
{
//注意→相除的话保留记得把1修改成1.0变成浮点型类型形式
sum1 = 1.0 / i + sum1;//sum1保存上一次值相加
sum2 = 1.0 / i - sum2;//sum2保存上一次值相加
}
printf("sum1 = %lf\n", sum1);
printf("sum2 = %lf\n", sum2);
return 0;
}第三十九题→代码
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
#include<assert.h>//assert的头文件
int My_strlen(const char *arr)
{
unsigned int Count = 0;//统计字符不可能是为负数的!
assert(arr!=NULL);//这里加入到断言就能确保我们输入字符串的时候不会是空指针
while (*arr != '\0')
{
Count++;//自增++
*arr++;//++,直到遇到'\0'就退出
}
return Count;//返回计算机长度
}
int main(void)
{
char enter[20] = { 0 };
printf("请输入字符串:");
scanf("%s", &enter);
int ret = My_strlen(enter);
printf("The total number of input strings:%d\n",ret);
return 0;
}第四十零题→代码
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<assert.h>
//2.模拟strlen()函数的使用
int my_strlen(char *str)
{
int count = 0;
while (*str != '\0')
{
*str++;
count++;
}
return count;
}
//1.实现逆序打印
void print(char *str)
{
assert(str != NULL);
int left = 0;
int right = my_strlen(str) - 1;
while (left <= right)
{
char tep = str[left];
str[left] = str[right];
str[right] = tep;
left++;
right--;
}
}
int main(void)
{
char arr[20] = { 0 };
puts("请输入字符串↓");
gets(arr);
print(arr);
printf("逆序の字符串↓\n%s\n", arr);
return 0;
}边栏推荐
- 一网打尽异步神器CompletableFuture
- LeetCode_ 67 (binary sum)
- The forked VM terminated without saying properly goodbye
- Which Internet companies are worth going to in Shenzhen for software testers [Special Edition for software testers]
- Loop invariant
- openGauss数据库源码解析系列文章—— 密态等值查询技术详解(下)
- 有一个强大又好看的,赛过Typora,阿里开发的语雀编辑器
- 浅谈Dataset和Dataloader在加载数据时如何调用到__getitem__()函数
- Qingda KeYue rushes to the science and Innovation Board: the annual revenue is 200million, and it is proposed to raise 750million
- 【NVMe2.0b 14-9】NVMe SR-IOV
猜你喜欢

家用电器行业商业供应链协同平台解决方案:供应链系统管理精益化,助推企业智造升级

PyTorch二分类时BCELoss,CrossEntropyLoss,Sigmoid等的选择和使用

Niuke: intercepting missiles

SaaS multi tenant solution for FMCG industry to build digital marketing competitiveness of the whole industry chain

网上电子元器件采购商城:打破采购环节信息不对称难题,赋能企业高效协同管理
![Which Internet companies are worth going to in Shenzhen for software testers [Special Edition for software testers]](/img/c2/a5f5fe17a6bd1f6f9df828ddd224d6.png)
Which Internet companies are worth going to in Shenzhen for software testers [Special Edition for software testers]

乌卡时代下,企业供应链管理体系的应对策略

Shen Ziyu, nouveau Président de Meizu: M. Huang Zhang, fondateur de Meizu, agira comme conseiller stratégique pour les produits scientifiques et technologiques de Meizu

Chow Tai Fook fulfills the "centenary commitment" and sincerely serves to promote green environmental protection

世界环境日 | 周大福用心服务推动减碳环保
随机推荐
Faire un clip vidéo auto - média deux fois, comment clip n'est pas considéré comme une infraction
Why do mechanical engineers I know complain about low wages?
PyTorch二分类时BCELoss,CrossEntropyLoss,Sigmoid等的选择和使用
R语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用coef函数获取模型中每个变量(自变量改变一个单位)对应的对数优势比(log odds ratio)
分享 12 个最常用的正则表达式,能解决你大部分问题
LeetCode_ 67 (binary sum)
Introduction, installation, introduction and detailed introduction to postman!
Is it OK to open the securities account on the excavation finance? Is it safe?
Chow Tai Fook fulfills the "centenary commitment" and sincerely serves to promote green environmental protection
After the microservice project is deployed, static resources and files uploaded to upload cannot be accessed. Solution
Total amount analysis accounting method and potential method - allocation analysis
Is the securities account given by the head teacher of qiniu school safe? Can I open an account?
Thymeleaf th:with局部变量的使用
What about SSL certificate errors? Solutions to common SSL certificate errors in browsers
There is a powerful and good-looking language bird editor, which is better than typora and developed by Alibaba
【学习笔记】图的连通性与回路
The function of qualifier in C language
[learning notes] connectivity and circuit of graph
Longest common subsequence dynamic programming
Implement a blog system -- using template engine technology