统计信息

  • 访问数:14529
  • 博客数:143
  • 建立时间:2008-01-05
  • 更新时间:2008-10-15
我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!

P4Q9

2008-02-14 14:59:46

天气: 晴朗 心情: 高兴

/*P4Q9
 * Name:Wang Chaoran
 * Description:(Computing p) You can approximate by using the following series
 */

public class P4Q9
{
  public static void main(String[] args)
  {
    //Compute the pi
    for(double i=10000;i<=100000;i+=10000)
    {
      double p = 0;
     for(double j=1;j<=2*i+1;j+=2)
     {
       if(j%4==1)
       {
       p += 4 * 1/j;
       }
       else
       {
        p -= 4 * 1/j;
       }
      
       }
     //Display the pi
     System.out.println("If i = "+i+" p = "+ p);
    }
  
   
  }
}

/*P4Q9
 * Name:Wang Chaoran
 * Description:(Computing p) You can approximate by using the following series
 */

public class P4Q9
{
  public static void main(String[] args)
  {
    //Compute the pi
    for(double i=10000;i<=100000;i+=10000)
    {
      double p = 4;
     for(double j=2;j<=i;j+=2)
     {
       p+=4*(-1/(2*j-1)+1/(2*j+1));
      
       }
     //Display the pi
     System.out.println("If i = "+i+" p = "+ p);
    }
  
   
  }
}


 


加入收藏 编辑 审核

TAG: computing

我来说两句

OPEN

Powered by X-Space 1.2 © 2001-2006 Comsenz Technology Ltd