当前位置:网站首页>[C question set] of Ⅷ
[C question set] of Ⅷ
2022-07-05 14:34:00 【InfoQ】
write in front
Question 36 → Find the Fibonacci number ! Enter a number to find the corresponding Fibonacci sequence
Question 37 → Calculation 1 To 100 Number of numbers , Find the number in one digit 9 And the ten digit number 9 Print it out , And use Count Calculate the sum of the printed numbers
Question 38 → Separate calculation 1/1+1+2/1+3/1+4/1+5/+......+1/99+1/100 and 1/1-1/2-1/3-1/4-1-5-......-1/99-1/100 Value
Question 39 → Simulate the implementation of string functions , Any input ~ Find the length of string function
size_t strlen ( const char * str );
Question 40 zero → Any input string to print in reverse order , Out of commission C Its own string library function
Question 36 → Code
#include<stdio.h>
// Fibonacci sequence : The sum of the first two numbers is equal to the third number
/* 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)// Only the third party is required 2 The Fibonacci number will be executed after three months while loop
{
c = a + b;
a = b;
b = c;
n--;//n = n - 1; Each execution is reduced to n=2 until .
}
return c;
}
int main(void)
{
int n = 0;
int let = 0;
printf(" Please enter a number :");
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(" Please enter the required number :");
scanf("%d", &n);
printf("%d\n", fib(n));
return 0;
}
Question 37 → Code
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main(void)
{
int i = 0;
int Count = 0;
for (i = 0; i < 101; i++)
{
// bits
if (i % 10 == 9)
{
printf("%d ", i);
Count++;
}
// ten
if (i / 10 == 9)
{
printf("%d ", i);
Count++;
}
}
printf("\nCount=%d\n", Count);
return 0;
}
Question 38 → Code
#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++)
{
// Be careful → If you divide, keep in mind 1 Modified into 1.0 Become a floating point type
sum1 = 1.0 / i + sum1;//sum1 Save the last value and add
sum2 = 1.0 / i - sum2;//sum2 Save the last value and add
}
printf("sum1 = %lf\n", sum1);
printf("sum2 = %lf\n", sum2);
return 0;
}
Question 39 → Code
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
#include<assert.h>//assert The header file
int My_strlen(const char *arr)
{
unsigned int Count = 0;// Statistical characters cannot be negative !
assert(arr!=NULL);// By adding assertions here, we can ensure that when we enter a string, it will not be a null pointer
while (*arr != '\0')
{
Count++;// Self increasing ++
*arr++;//++, Until I met '\0' Quit
}
return Count;// Returns the length of the computer
}
int main(void)
{
char enter[20] = { 0 };
printf(" Please enter the string :");
scanf("%s", &enter);
int ret = My_strlen(enter);
printf("The total number of input strings:%d\n",ret);
return 0;
}
Question 40 → Code
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<assert.h>
//2. simulation strlen() Use of functions
int my_strlen(char *str)
{
int count = 0;
while (*str != '\0')
{
*str++;
count++;
}
return count;
}
//1. Realize reverse printing
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(" Please enter the string ↓");
gets(arr);
print(arr);
printf(" The reverse の character string ↓\n%s\n", arr);
return 0;
}
边栏推荐
- Disjoint Set
- 两个BI开发,3000多张报表?如何做的到?
- 浅谈Dataset和Dataloader在加载数据时如何调用到__getitem__()函数
- Topology visual drawing engine
- 分享 20 个稀奇古怪的 JS 表达式,看看你能答对多少
- Structure - C language
- Is the securities account given by the head teacher of qiniu school safe? Can I open an account?
- LeetCode_ 3 (longest substring without repeated characters)
- Catch all asynchronous artifact completable future
- The forked VM terminated without saying properly goodbye
猜你喜欢
Online electronic component purchasing Mall: break the problem of information asymmetry in the purchasing process, and enable enterprises to effectively coordinate management
安装配置Jenkins
如何将电脑复制的内容粘贴进MobaXterm?如何复制粘贴
Thymeleaf 模板的创建与使用
FR练习题目---综合题
两个BI开发,3000多张报表?如何做的到?
区间 - 左闭右开
用 Go 跑的更快:使用 Golang 为机器学习服务
PyTorch二分类时BCELoss,CrossEntropyLoss,Sigmoid等的选择和使用
分享 12 个最常用的正则表达式,能解决你大部分问题
随机推荐
Lepton 无损压缩原理及性能分析
启牛证券账户怎么开通,开户安全吗?
LeetCode_ 3 (longest substring without repeated characters)
Introduction, installation, introduction and detailed introduction to postman!
申请代码签名证书时如何选择合适的证书品牌?
R語言ggplot2可視化:可視化折線圖、使用theme函數中的legend.position參數自定義圖例的比特置
PostgreSQL 13 installation
PHP - fatal error: allowed memory size of 314572800 bytes exhausted
区间 - 左闭右开
世界环境日 | 周大福用心服务推动减碳环保
leetcode:881. 救生艇
CyCa children's physical etiquette Ningbo training results assessment came to a successful conclusion
Thymeleaf common functions
ASP. Net large takeout ordering system source code (PC version + mobile version + merchant version)
通过npm 或者 yarn安装依赖时 报错 出现乱码解决方式
Redis如何实现多可用区?
useMemo,memo,useRef等相关hooks详解
LeetCode_ 69 (square root of x)
FR练习题目---综合题
Principle and performance analysis of lepton lossless compression