当前位置:网站首页>[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;
}边栏推荐
- 美国费城发生“安全事故” 2名警察遭枪杀
- 如何将电脑复制的内容粘贴进MobaXterm?如何复制粘贴
- C language -- structure and function
- CPU设计实战-第四章实践任务三用前递技术解决相关引发的冲突
- LeetCode_ 67 (binary sum)
- What about SSL certificate errors? Solutions to common SSL certificate errors in browsers
- 手写promise与async await
- FR练习题目---综合题
- R language dplyr package select function, group_ By function, mutate function and cumsum function calculate the cumulative value of the specified numerical variable in the dataframe grouping data and
- 乌卡时代下,企业供应链管理体系的应对策略
猜你喜欢

非技术部门,如何参与 DevOps?

Microframe technology won the "cloud tripod Award" at the global Cloud Computing Conference!

快消品行业SaaS多租户解决方案,构建全产业链数字化营销竞争力

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

Implement a blog system -- using template engine technology

ASP.NET大型外卖订餐系统源码 (PC版+手机版+商户版)

Niuke: intercepting missiles

实现一个博客系统----使用模板引擎技术

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

LeetCode_ 2 (add two numbers)
随机推荐
openGauss数据库源码解析系列文章—— 密态等值查询技术详解(下)
日化用品行业智能供应链协同系统解决方案:数智化SCM供应链,为企业转型“加速度”
The forked VM terminated without saying properly goodbye
FR练习题目---简单题
PyTorch二分类时BCELoss,CrossEntropyLoss,Sigmoid等的选择和使用
周大福践行「百周年承诺」,真诚服务推动绿色环保
Fonctions communes de thymeleaf
分享 20 个稀奇古怪的 JS 表达式,看看你能答对多少
Implement a blog system -- using template engine technology
freesurfer运行完recon-all怎么快速查看有没有报错?——核心命令tail重定向
The simplest way to open more functions without certificates
Thymeleaf 模板的创建与使用
选择排序和冒泡排序
世界环境日 | 周大福用心服务推动减碳环保
【NVMe2.0b 14-9】NVMe SR-IOV
729. 我的日程安排表 I :「模拟」&「线段树(动态开点)」&「分块 + 位运算(分桶)」
[learning notes] connectivity and circuit of graph
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
手写promise与async await
Niuke: intercepting missiles