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

    Problem Description
    A simple mathematical formula for e is

    where n is allowed to go to infinity. This can actually yield very accurate approximations of e using relatively small values of n.
     
    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 Output
    n e - -----------
    0 1
    1 2
    2 2.5
    3 2.666666667
    4 2.708333333
    #include<iostream>
    #include<stdio.h>
    using namespace std;
    int main()
    {
        int i,sum;
        double a[100];
        sum=1;
        for(i=0;i<=9;i++)
        {
               if(i==0)
                   a[i]=1;
               else
            {
                      sum=sum*i;
                a[i]=a[i-1]+1.0/sum;
            }
        }
        printf("n e\n- -----------\n");
        for(i=0;i<10;i++)
        {
            cout<<i<<" ";
            if(i<2)
                printf("%.0lf\n",a[i]);//小数点后保留0位有效数值
            else if(i==2)
                printf("%.1lf\n",a[i]);//小数点后保留1位有效数值
            else
                printf("%.09lf\n",a[i]);//小数点后保留9位有效数值
        }
        return 0;
    }
  • 相关阅读:
    等待
    QToolBox工具箱
    组合框QGroupBox
    把ui界面加入到工程中
    assistant文档
    日期与时间控件QDate, QTime, QDateTime
    日历控件QCalendarWidget
    液晶数字显示屏QLCDNumbe
    ffpanel --ffmpeg的GUI,让ffmpeg离开黑黑的命令行
    使用Nginx反向代理和proxy_cache缓存搭建CDN服务器加快Web访问速度
  • 原文地址:https://www.cnblogs.com/heqinghui/p/2609351.html
Copyright © 2011-2022 走看看