当前位置:网站首页>[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;
}
边栏推荐
- R language ggplot2 visualization: visual line graph, using legend in theme function The position parameter defines the position of the legend
- 有一个强大又好看的,赛过Typora,阿里开发的语雀编辑器
- CYCA少儿形体礼仪 宁波市培训成果考核圆满落幕
- 矩阵链乘 - 动态规划实例
- Principle and performance analysis of lepton lossless compression
- 危机重重下的企业发展,数字化转型到底是不是企业未来救星
- PHP - fatal error: allowed memory size of 314572800 bytes exhausted
- 01. Solr7.3.1 deployment and configuration of jetty under win10 platform
- Strong connection component
- FR练习题目---简单题
猜你喜欢
How to deeply understand the design idea of "finite state machine"?
Niuke: intercepting missiles
leetcode:881. lifeboat
网上电子元器件采购商城:打破采购环节信息不对称难题,赋能企业高效协同管理
How to protect user privacy without password authentication?
How does redis implement multiple zones?
Share 20 strange JS expressions and see how many correct answers you can get
日化用品行业智能供应链协同系统解决方案:数智化SCM供应链,为企业转型“加速度”
非技术部门,如何参与 DevOps?
How can non-technical departments participate in Devops?
随机推荐
申请代码签名证书时如何选择合适的证书品牌?
美国费城发生“安全事故” 2名警察遭枪杀
MySQL user-defined function ID number to age (supports 15 / 18 digit ID card)
C语言中限定符的作用
不相交集
Structure - C language
LeetCode_ 67 (binary sum)
Intelligent supply chain collaboration system solution for daily chemical products industry: digital intelligent SCM supply chain, which is the "acceleration" of enterprise transformation
js亮瞎你眼的日期选择器
Thymeleaf th:classappend属性追加 th:styleappend样式追加 th:data-自定义属性
直播预告|如何借助自动化工具落地DevOps(文末福利)
Assembly language
世界环境日 | 周大福用心服务推动减碳环保
R language ggplot2 visualization: use ggplot2 to visualize the scatter diagram, and use the labs parameter to customize the X axis label text (customize X axis labels)
无密码身份验证如何保障用户隐私安全?
Introduction, installation, introduction and detailed introduction to postman!
Niuke: intercepting missiles
PMP考试20天能通过吗?
dynamic programming
实现一个博客系统----使用模板引擎技术