Pi的精准算法
π=4*(1-1/3+1/5-1/7+1/9-…-1/(2*i-1)+1/(2*i+1))
位数越多pi的值就越精准。实现算法
package com.sysi.cn;
//π=4*(1-1/3+1/5-1/7+1/9-…-1/(2*i-1)+1/(2*i+1))
public class PiDemo {
public static void main(String[] args) {
float pi=0;
float j=0;
float o=0;
for(float i=2;i<10000000;i=i+2){
j=j+1/(float)(2*i-1);
o=o+1/(float)(2*i+1);
}
pi=4*(1-j+o);
System.out.println(pi);
}
}
相关推荐
湾区人工智能 2020-11-20
Pokemogo 2020-11-16
baijingjing 2020-11-16
baijingjing 2020-11-15
Site 2020-11-07
lwnylslwnyls 2020-11-06
justaipanda 2020-11-05
MachineIntellect 2020-11-02
xueyuediana 2020-10-30
GeraldJones 2020-10-30
Tips 2020-10-29
baijingjing 2020-10-28
baijingjing 2020-10-27
硕鼠 2020-10-26
playoffs 2020-10-26
scuyxi 2020-10-25
playoffs 2020-10-25
yise001 2020-10-23