当前位置:网站首页>用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次方即可
边栏推荐
- 你了解数据是如何存储的吗?(C整型和浮点型两类)
- 公网集群对讲+GPS可视追踪|助力物流行业智能化管理调度
- IT 技术电子书 收藏
- 【C】 Summary of wrong questions in winter vacation
- Tita OKR: a dashboard to master the big picture
- Leetcode t40: combined sum II
- What is the material of 16MnDR, the minimum service temperature of 16MnDR, and the chemical composition of 16MnDR
- Do you know how data is stored? (C integer and floating point)
- Introduction to R language
- 目标检测的yolov3、4、5、6总结
猜你喜欢

factory type_id::create过程解析

Advanced level of C language pointer (Part 1)

【华为机试真题详解】判断字符串子序列【2022 Q1 Q2 | 200分】

Do you know how data is stored? (C integer and floating point)

R语言入门

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

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

Field agricultural irrigation system

19Mn6 German standard pressure vessel steel plate 19Mn6 Wugang fixed binding 19Mn6 chemical composition

Guidelines and principles of did
随机推荐
机动目标跟踪——当前统计模型(CS模型)扩展卡尔曼滤波/无迹卡尔曼滤波 matlab实现
Mavros sends a custom topic message to Px4
Advanced level of C language pointer (Part 1)
Yolov3, 4, 5 and 6 Summary of target detection
明明设计的是高带宽,差点加工成开路?
Leetcode t31: prochain arrangement
Foundation: 2 The essence of image
Field agricultural irrigation system
[no title] free test questions for constructor municipal direction general foundation (constructor) and theoretical test for constructor municipal direction general foundation (constructor) in 2022
Model and view of QT
Guidelines and principles of did
基于Gazebo的无人机管道检测
[detailed explanation of Huawei machine test] judgment string subsequence [2022 Q1 Q2 | 200 points]
Leetcode t39: combined sum
Do you know how data is stored? (C integer and floating point)
《单片机原理与应用》——并行IO口原理
There are many problems in sewage treatment, and the automatic control system of pump station is solved in this way
NIO-零拷贝
C basic knowledge review (Part 4 of 4)
Burpsuite -- brute force cracking of intruder