计算 1+1/2!+1/3!+1/4!+...1/20!=?

    double jiecheng=1;
    double sum=0;
    int j=0;
    for (int i = 1; i <=20; i++) 
    {     
    do 
    {    
       j++;
       jiecheng=jiecheng*j;
    
     }
       while (j<i);    
     // System.out.println(jiecheng);
      sum=sum+1/jiecheng;
    }
      System.out.println("1+1/2!+1/3!+1/4!+...1/20!="+sum);

posted @ 2016-05-09 13:29  凌零聆  阅读(367)  评论(0编辑  收藏  举报