Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7707521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:22:54+00:00 2026-06-01T00:22:54+00:00

I have been trying to approximate e using series representation to get as many

  • 0

I have been trying to approximate e using series representation to get as many precision digits as possible using the code below, but no matter how many terms I compute, the number of precision digits seems to remain the same. ie:

2.71828198432922363281250000000000000000000000000000

Is it my approach that’s wrong?
Here is the code:

  1 #include <stdio.h>
  2 #include <iostream>
  3 #include <math.h>
  4 using namespace std;
  5 
  6 float factorial (float a)
  7 {
  8         if (a > 1)
  9         {
 10                 return (a * factorial (a-1));
 11         } else
 12         {
 13                 return 1;
 14         }
 15 }
 16 
 17 int main()
 18 {
 19         float sum  = 0;
 20         int range=100000;
 21 
 22         for (int i=0; i<=range;i++)
 23         {
 24                 sum += pow(-1,i)/factorial(i);
 25         }
 26         sum = pow(sum,-1);
 27         printf("%4.50f\n", sum);
 28 } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T00:22:55+00:00Added an answer on June 1, 2026 at 12:22 am

    To get more exact digits, you should write your on data class which store more digit, say, 1000 digits. The hardest part is to wirte the +, -, *, / operations.

    If what you want is just to experiment with the math formula, you can choose another language, such as Python. It has data types like Decimal, Fraction that can do more precise calculating.

    I love math so I do write a python script to test the formula:

    from decimal import Decimal, getcontext
    prec = 100
    getcontext().prec = prec
    
    fac = Decimal(1)/2
    sum = Decimal(0)
    eps = Decimal(0.1)
    eps = eps**prec
    
    realE = '2.71828182845904523536028747135266249775724709369995'
    
    i = 3
    while 1:
        ds = fac - fac/i
        sum += ds
        if ds < eps: break
        fac /= i * (i+1)
        i += 2
    
    print 'After %d iteration:' % i
    print realE
    print str(1/sum)
    

    Here’s the result:

    After 71 iteration:
    2.71828182845904523536028747135266249775724709369995
    2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166429
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to get all rows from the SQLite database. But I
I have been trying to Deserialize an XmlResponse using RestSharp, but have been unable
I have been trying to implement Win32's MessageBox using GTK. The app uses SDL/OpenGL,
I have been trying to get around this error for a day now and
I have been trying to find newly added entities on a context by using
I have been using the below to do a color conversion if @image.colorspace ==
I have been trying to install the R language with homebrew but when I
I have been trying to figure this out, but google wasn't turning up any
Have been trying to get integration testing working with my seam project and the
I have been trying for what seems like two days now to get my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.