当前位置:网站首页>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 .
边栏推荐
- [regular] judgment, mobile number, ID number
- 代码回滚,你真的理解吗?
- 明汯投资裘慧明:长期优异超额的背后考验的是团队的投研能力和策略的完整性
- Maximum continuous subsequence (day 77)
- Plato farm brings a new experience to community users through the LAAS protocol elephant swap
- 【无标题】JDBC连接数据库读超时
- Textbox in easyUI inserts content at the cursor position
- Learning and understanding of four special data types of redis
- Machine learning [Matplotlib]
- How to optimize MySQL
猜你喜欢

深圳家具展首日,金可儿展位三大看点全解锁!

Characteristics and determination scheme of Worthington pectinase

数字孪生应用及意义对电力的主要作用,概念价值。

Number of 0 at the end of factorial

Application, addition and deletion of B-tree

477-82(236、61、47、74、240、93)

Director of meta quest content ecology talks about the original intention of APP lab design

Process analysis of object creation

redis入门练习

关于使用hyperbeach出现/bin/sh: 1: packr2: not found的解决方案
随机推荐
Maximum continuous subsequence (day 77)
Tool class of localdatetime sorted out by yourself
Connman introduction
Deeply understand the underlying data structure and algorithm of MySQL index
Redis source code learning (33), command execution process
Redis源码学习(33),命令执行过程
DataX无法连接对应的数据库(windows下可以,linux下失败)
Characteristics and experimental suggestions of abbkine abfluor 488 cell apoptosis detection kit
Contour detection based on OpenCV (1)
Characteristics and determination scheme of Worthington pectinase
Is Jiufang intelligent investment a regular company? Talk about Jiufang intelligent investment
MySQL underlying data structure
Source code analysis of openfeign
Installation and use of anti-virus software ClamAV
About the solution of using hyperbeach to appear /bin/sh: 1: packr2: not found
Binary tree (day 82)
九方智投是正规公司吗?一起聊聊九方智投
Practical application of digital twins: smart city project construction solution
Penetration test - post penetration - Trace cleaning
MySQL中文失败问题