当前位置:网站首页>7-15 calculation of PI
7-15 calculation of PI
2022-07-03 14:14:00 【Big fish】
According to the following relation , Find the value of pi , Until the value of the last item is less than the given threshold .
Input format :
The input gives less than... On one line 1 The threshold of .
Output format :
Output the approximate PI satisfying the threshold condition in one line , Output after decimal point 6 position .
sample input :
0.01
sample output :
3.132157
Code thinking :
#include <stdio.h>
int main()
{
double PI=1;
double t;
double num=1.0;
int i=1;
scanf("%lf",&t);
while(num>t) // Stop until the last item is less than the threshold
{
num=num*i/(i*2+1); // The numerator in each fraction is a factorial , The denominator is an arithmetic sequence
PI+=num;
i++;
}
printf("%.6f\n",PI*2);
return 0;
}
边栏推荐
- 玖逸云黑免费无加密版本源码
- 常见问题之PHP——ldap_add(): Add: Undefined attribute type in
- Global event bus
- concat和concat_ws()区别及group_concat()和repeat()函数的使用
- 28:第三章:开发通行证服务:11:在配置文件中定义属性,然后在代码中去获取;
- 消息订阅与发布
- [ACNOI2022]猜数
- Webpage connection database ~ simple implementation of addition, deletion, modification and query complete code
- Page generation QR code
- JVM object lifecycle
猜你喜欢
QT learning 25 layout manager (4)
Redis:Redis的数据结构、key的操作命令
Current situation, analysis and prediction of information and innovation industry
Scroll detection of the navigation bar enables the navigation bar to slide and fix with no content
“又土又穷”的草根高校,凭什么被称为“东北小清华”?
剑指 Offer 28. 对称的二叉树
修改数据库中的记录为什么报这个错
JS first summary
QT learning 19 standard dialog box in QT (top)
【吉林大学】考研初试复试资料分享
随机推荐
Redis: redis data structure and key operation commands
Redis:字符串类型数据的操作命令
超简单手机地图开发
JS download files through URL links
TS code automatically generates JS
Redis: operation command of string type data
JS shift operators (< <,> > and > > >)
MongoDB索引
Exercise 6-6 use a function to output an integer in reverse order
QT learning 24 layout manager (III)
The small project (servlet+jsp+mysql+el+jstl) completes a servlet with login function, with the operation of adding, deleting, modifying and querying. Realize login authentication, prevent illegal log
JS first summary
Redis: commandes d'action pour les données de type chaîne
PCB中常用快捷键
C language,%d% Difference between 2D%2d%02d
page owner特性浅析
Global event bus
JS get DPI, PX to cm, cm to PX
Collection of mobile adaptation related articles
Nucleic acid modified metal organic framework drug carrier | pcn-223 metal organic framework encapsulated ad adamantane | zif-8 encapsulated adriamycin (DOX)