zoukankan      html  css  js  c++  java
  • poj 1517 u Calculate e

    u Calculate e
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 19465   Accepted: 11362   Special Judge

    Description

    A simple mathematical formula for e is 
    e=Σ0<=i<=n1/i!

    where n is allowed to go to infinity. This can actually yield very accurate approximations of e using relatively small values of n.

    Input

    No input

    Output

    Output the approximations of e generated by the above formula for the values of n from 0 to 9. The beginning of your output should appear similar to that shown below.

    Sample Input

    no input

    Sample Output

    n e
    - -----------
    0 1
    1 2
    2 2.5
    3 2.666666667
    4 2.708333333
    ...

    #include<stdio.h>
    #include<string.h>
    #include<cstdio> 
    #include<string>
    #include<math.h>
    #include<algorithm>
    #define LL long long
    #define PI atan(1.0)*4
    #define DD double
    #define MAX 2002000
    #define mod 100
    #define dian 1.000000011
    #define INF 0x3f3f3f
    using namespace std;
    int main()
    {
        LL n,m,j,i,t,k;
        printf("n e
    ");
    	printf("- -----------
    ");
    	DD sum=0;
    	printf("0 1
    ");
    	for(i=1;i<=9;i++)
    	{
    		printf("%d ",i);
    		DD ans=1;
    		for(j=1;j<=i;j++)
    			ans*=j;
    		sum+=1/ans;
    		printf("%.10g
    ",sum+1);
    	} 
    	return 0;
    }
    

      

  • 相关阅读:
    @ResponseBody和@RequestBoby的作用
    项目Alpha冲刺Day9
    项目Alpha冲刺Day8
    项目Alpha冲刺Day7
    设计模式第三次作业
    项目Alpha冲刺Day6
    树莓派历程笔记
    项目Alpha冲刺Day5
    django获取ip与数据重复性判定
    在django模板中添加jquery
  • 原文地址:https://www.cnblogs.com/tonghao/p/5291301.html
Copyright © 2011-2022 走看看