qq_34418970 于 2016.04.21 13:17 提问

double n=3;
double PI;
double s=1/n;
double sum=1/3;
do
{

``````           sum = sum + s;
n = n + 2;
PI = 4 *(1-sum);
}
while (s < 0.000001);
Console.WriteLine(PI);*/
``````

1个回答

danielinbiti      2016.04.21 13:34
``````先理解算法
double n=3;
double PI;
double s=1/n;
int i = 1;
double sum=1;
do
{
i = i * -1;
s = 1 / n;
sum = sum + s*i;
n = n + 2;
}
while (s > 0.000001);
PI = 4 * sum;
Console.WriteLine(PI);
``````
qq_34418970 想了好久，还是想不明白，自己的意识上感觉是对的，还有题目上不是说1/n<0.000001时停止计算？

C语言代码，求高手解答，为什么没有错误，但是结果不对
#include #include char *cmonth(int month) { char str_month[]={ "Illegal Month" "January" "February" "March" "April" "May" "June" "July" "August" "September" "October" "November"

#include #include main() {  int denominator,flag;  double item,pi;  flag,denominator=1,item=1.0,pi=0;  while(fabs(item)>=0.0001){         item=flag*1.0/denominator;         pi=pi+flag;

1067 例题5-7 求圆周率pi的近似值

Spark实例演示之SparkPi
1.贴上源码 def main(args: Array[String]) { val conf = new SparkConf().setAppName("Spark Pi").setMaster("spark://hadoop1:7077").setJars(List("/home/kaiseu/MyProject/IdeaProjects/week2/out/artifacts/week2
Linux多线程计算Pi函数（互斥没起作用？？？）
#include <stdio.h> #include <stdlib.h> #include <pthread.h> #include <sys/time.h>pthread_mutex_t mutexsum; #define thread_count 4 double sum;void* start_thread(void *rank);void* start_thread(void *ra
Linux下多线程通过蒙特卡洛法来求取pi值

**基础题1、**通过键盘输入声明初始值一个圆柱体的高和底面半径，PI值是3.14，求圆柱体的体积，并显示输出圆柱体的体积；V=π（r^2）h。

【蓝桥杯】算法提高 7-2求arccos值