当前位置:网站首页>【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;
}边栏推荐
- Thymeleaf 模板的创建与使用
- 总量分析 核算方法和势方法 - 分摊分析
- FR练习题目---综合题
- LeetCode_ 69 (square root of x)
- Qingda KeYue rushes to the science and Innovation Board: the annual revenue is 200million, and it is proposed to raise 750million
- Share 20 strange JS expressions and see how many correct answers you can get
- Longest common subsequence dynamic programming
- R語言ggplot2可視化:可視化折線圖、使用theme函數中的legend.position參數自定義圖例的比特置
- R语言ggplot2可视化密度图:按照分组可视化密度图、自定义配置geom_density函数中的alpha参数设置图像透明度(防止多条密度曲线互相遮挡)
- CPU设计相关笔记
猜你喜欢

Online electronic component purchasing Mall: break the problem of information asymmetry in the purchasing process, and enable enterprises to effectively coordinate management

区间 - 左闭右开

【NVMe2.0b 14-9】NVMe SR-IOV

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

Why do mechanical engineers I know complain about low wages?

超级哇塞的快排,你值得学会!

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

Loop invariant

Qingda KeYue rushes to the science and Innovation Board: the annual revenue is 200million, and it is proposed to raise 750million

World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
随机推荐
【学习笔记】阶段测试1
R language uses boxplot function in native package (basic import package, graphics) to visualize box plot
SaaS multi tenant solution for FMCG industry to build digital marketing competitiveness of the whole industry chain
无密码身份验证如何保障用户隐私安全?
Thymeleaf th:classappend属性追加 th:styleappend样式追加 th:data-自定义属性
PMP考试20天能通过吗?
Thymeleaf th:with use of local variables
Niuke: intercepting missiles
总量分析 核算方法和势方法 - 分摊分析
R language ggplot2 visualization: visual line graph, using legend in theme function The position parameter defines the position of the legend
Matrix chain multiplication dynamic programming example
有一个强大又好看的,赛过Typora,阿里开发的语雀编辑器
Disjoint Set
01. Solr7.3.1 deployment and configuration of jetty under win10 platform
Thymeleaf 常用函数
Sharing the 12 most commonly used regular expressions can solve most of your problems
Topology可视化绘图引擎
freesurfer运行完recon-all怎么快速查看有没有报错?——核心命令tail重定向
R language ggplot2 visualization: gganimate package is based on Transition_ The time function creates dynamic scatter animation (GIF) and uses shadow_ Mark function adds static scatter diagram as anim
一网打尽异步神器CompletableFuture