当前位置:网站首页>用C语言编程:用公式计算:e≈1+1/1!+1/2! …+1/n!,精度为10-6
用C语言编程:用公式计算:e≈1+1/1!+1/2! …+1/n!,精度为10-6
2022-07-01 08:33:00 【用编程写诗】
先上代码:
#include<stdio.h>
void main()
{
float f(float x);//函数声明
double b=1;
float j;
for(j=1;(1.0/f(j))>1.0e-6;j++)
{
b=b+1.0/f(j);
}
printf("%f\n",b);
}
float f(float x)
{
float i;
float y=1;
for(i=1;i<=x;i++)
y*=i;
return y;
}
这道题就是采用了一个求阶乘的函数,在主函数对他进行调用然后保证最后一项>10-6次方即可
边栏推荐
- Leetcode T39: 组合总和
- Principle and application of single chip microcomputer - principle of parallel IO port
- 《单片机原理及应用》-片外拓展
- 性能提升2-3倍!百度智能云第二代昆仑芯服务器上线
- 2022 Chinese cook (technician) simulation test and Chinese cook (technician) practice test video
- MATLAB小技巧(23)矩阵分析--模拟退火
- Review of week 280 of leetcode
- MD文档中插入数学公式,Typora中插入数学公式
- Count number of rows per group and add result to original data frame
- MATLAB【函数求导】
猜你喜欢
随机推荐
What is the material of 16MnDR, the minimum service temperature of 16MnDR, and the chemical composition of 16MnDR
win7 pyinstaller打包exe 后报错 DLL load failed while importing _socket:参数错误
Intelligent water and fertilizer integrated control system
Huawei machine test questions column subscription Guide
Foundation: 3 Opencv getting started images and videos
Advanced API
Suivi des cibles de manoeuvre - - mise en oeuvre du modèle statistique actuel (modèle CS) filtre Kalman étendu / filtre Kalman sans trace par MATLAB
Luogu p3799 demon dream stick
Yolov5进阶之七目标追踪最新环境搭建
个人装修笔记
5mo3 UHI HII HII 17mn4 19Mn6 executive standard
How to recruit Taobao anchor suitable for your own store
Agrometeorological environment monitoring system
What is 1cr0.5mo (H) material? 1cr0.5mo (H) tensile yield strength
Comprehensive experiment Li
Principle and application of single chip microcomputer - off chip development
【无标题】
Li Kou 1358 -- number of substrings containing all three characters (double pointer)
避免按钮重复点击的小工具bimianchongfu.queren()
Foundation: 2 The essence of image





![Thread safety analysis of [concurrent programming JUC] variables](/img/f9/a3604bec6f7e5317dd2c578da73018.jpg)



