当前位置:网站首页>C language introduction practice (12): find the value of natural constant e
C language introduction practice (12): find the value of natural constant e
2022-07-27 03:52:00 【liberg】
This is a 《C Language introduction practice 》 Series No 12 piece .
Last one :C Language introduction practice (11): Enter a set of positive integers , Find the sum of inverse numbers
List of articles
subject
Using the formula :
e = 1 0 ! + 1 1 ! + 1 2 ! + . . . + 1 n ! + . . . e=\frac{1}{0!}+\frac{1}{1!}+\frac{1}{2!}+...+\frac{1}{n!}+... e=0!1+1!1+2!1+...+n!1+...
Find the natural constant e, The control accuracy is required to be 0.000001, Please program to solve this problem .
requirement
There is no need to enter , Results output only e The value of the can .
Reference code
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
float e = 1;// The first 1 term ,1/0!
float d = 1;
int i;
int pro = 1;// The denominator
for(i=1;d>=1e-6;i++) {
pro *= i;
d = (float)1/pro;
e += d;
}
printf("%f", e);//2.718282
return 0;
}
Code duplicate
At first ,e Initialize to the value of the first item , And then use it n! = n * (n-1)! The nature of ,for In the cycle, calculate the denominator of each item starting from the second item .
边栏推荐
- 数字孪生应用及意义对电力的主要作用,概念价值。
- C language force deduction question 43 string multiplication. Optimized vertical
- Briefly sort out the dualpivotquicksort
- Network security / penetration testing tool awvs14.9 download / tutorial / installation tutorial
- Number of square arrays (day 81)
- J-3-point practice in the second game of 2022 Niuke multi school
- The application and significance of digital twins are the main role and conceptual value of electric power.
- Minimum ticket price (day 80)
- If the detailed explanation is generated according to the frame code
- 在typora中插入图片和视频
猜你喜欢

Do you really understand code rollback?

【无标题】JDBC连接数据库读超时

app端接口用例设计方法和测试方法

Worthington papain dissociation system solution

Quick sequencing and optimization

DTS is equipped with a new self-developed kernel, which breaks through the key technology of the three center architecture of the two places Tencent cloud database

FastBoot brush machine
![Machine learning [Matplotlib]](/img/d1/31ec2f96ca96465c6863798c7db179.jpg)
Machine learning [Matplotlib]

次轮Okaleido Tiger即将登录Binance NFT,引发社区热议

复盘:DFS与BFS的主要区别,在思想上的区别,代码实现上的区别
随机推荐
The function and application of lpci-252 universal PCI interface can card
The application and significance of digital twins are the main role and conceptual value of electric power.
03.获取网页源代码
Design method and test method of APP interface use case
面试题:String类中三种实例化对象的区别
Code review pyramid
Insert pictures and videos in typera
redis入门练习
榕树贷款,
Meta Quest内容生态总监谈App Lab设计初衷
Redis source code learning (33), command execution process
Prime factorization -- C (GCC) -- PTA
Take you to know what Web3.0 is
C language force deduction question 43 string multiplication. Optimized vertical
深圳家具展首日,金可儿展位三大看点全解锁!
Use websocket to realize a web version of chat room (fishing is more hidden)
Feitengtengrui d2000 won the "top ten hard core technologies" award of Digital China
复盘:DFS与BFS的主要区别,在思想上的区别,代码实现上的区别
Quick sequencing and optimization
typescript ts 基础知识之接口、泛型