当前位置:网站首页>用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次方即可
边栏推荐
- CPU design practice - Chapter 4 practical tasks - simple CPU reference design and debugging
- Provincial election + noi part I dynamic planning DP
- MATLAB小技巧(23)矩阵分析--模拟退火
- 我想知道手机注册股票开户的流程?另外,手机开户安全么?
- Luogu p3799 demon dream stick
- SPL-安装与基本使用(二)
- Leetcode T39: 组合总和
- 明明设计的是高带宽,差点加工成开路?
- Audio-AudioRecord create(一)
- How to recruit Taobao anchor suitable for your own store
猜你喜欢

MAVROS发送自定义话题消息给PX4

What is the material of 16mo3 steel plate? What is the difference between 16mo3 and Q345R?

The data analyst will be ruined without project experience. These 8 project resources will not be taken away

Li Kou 1358 -- number of substrings containing all three characters (double pointer)

SPL Introduction (I)

Internet of things technology is widely used to promote intelligent water automation management

Matlab tips (16) consistency verification of matrix eigenvector eigenvalue solution -- analytic hierarchy process

factory type_id::create过程解析

TypeError: __init__() got an unexpected keyword argument ‘autocompletion‘

Glitch Free时钟切换技术
随机推荐
yolov5训练可视化指标的含义
分享2022上半年我读过的7本书
TypeError: __ init__ () got an unexpected keyword argument ‘autocompletion‘
Glitch Free时钟切换技术
挖财打新股安全吗
机动目标跟踪——当前统计模型(CS模型)扩展卡尔曼滤波/无迹卡尔曼滤波 matlab实现
Leetcode T40: 组合总和II
What is the material of 15CrMoR, mechanical properties and chemical analysis of 15CrMoR
Matlab tips (16) consistency verification of matrix eigenvector eigenvalue solution -- analytic hierarchy process
Advanced API
Leetcode T34: 在排序数组中查找元素的第一个和最后一个位置
1.jetson与摄像头的对接
factory type_id::create过程解析
Manually dig XSS vulnerabilities
Matlab tips (23) matrix analysis -- simulated annealing
Yolov5 advanced six target tracking environment construction
MATLAB【函数和图像】
3、Modbus通讯协议详解
Internet of things technology is widely used to promote intelligent water automation management
Matlab [functions and images]