当前位置:网站首页>【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;
}边栏推荐
- R language uses the multinom function of NNET package to build an unordered multi classification logistic regression model, and uses the coef function to obtain the log odds ratio corresponding to eac
- Longest common subsequence dynamic programming
- Show strength. In this way, the mobile phone will not be difficult to move forward
- 动态规划
- How does redis implement multiple zones?
- 申请代码签名证书时如何选择合适的证书品牌?
- CyCa children's physical etiquette Ningbo training results assessment came to a successful conclusion
- Explain Vue's plan to clean up keepalive cache in time
- What about SSL certificate errors? Solutions to common SSL certificate errors in browsers
- openGauss数据库源码解析系列文章—— 密态等值查询技术详解(下)
猜你喜欢

How can non-technical departments participate in Devops?

PHP - fatal error: allowed memory size of 314572800 bytes exhausted

黑马程序员-软件测试-10阶段2-linux和数据库-44-57为什么学习数据库,数据库分类关系型数据库的说明Navicat操作数据的说明,Navicat操作数据库连接说明,Navicat的基本使用,

FR练习题目---综合题

周大福践行「百周年承诺」,真诚服务推动绿色环保

Introduction, installation, introduction and detailed introduction to postman!

Why do mechanical engineers I know complain about low wages?

Section - left closed right open

Thymeleaf th:classappend attribute append th:styleappend style append th:data- custom attribute

非技术部门,如何参与 DevOps?
随机推荐
Which Internet companies are worth going to in Shenzhen for software testers [Special Edition for software testers]
FR练习题目---综合题
Webrtc learning (II)
How to choose the appropriate certificate brand when applying for code signing certificate?
Thymeleaf th:classappend属性追加 th:styleappend样式追加 th:data-自定义属性
SaaS multi tenant solution for FMCG industry to build digital marketing competitiveness of the whole industry chain
CPU设计实战-第四章实践任务三用前递技术解决相关引发的冲突
动态规划
日化用品行业智能供应链协同系统解决方案:数智化SCM供应链,为企业转型“加速度”
Catch all asynchronous artifact completable future
如何将电脑复制的内容粘贴进MobaXterm?如何复制粘贴
[learning notes] stage test 1
Online electronic component purchasing Mall: break the problem of information asymmetry in the purchasing process, and enable enterprises to effectively coordinate management
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
无密码身份验证如何保障用户隐私安全?
R语言ggplot2可视化:gganimate包基于transition_time函数创建动态散点图动画(gif)、使用shadow_mark函数为动画添加静态散点图作为动画背景
Discussion on memset assignment
Thymeleaf common functions
Isn't it right to put money into the external market? How can we ensure safety?
Solution of commercial supply chain collaboration platform in household appliance industry: lean supply chain system management, boosting enterprise intelligent manufacturing upgrading