473,385 Members | 1,384 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Calculating exponential function

Use the followingformula to calculate the very important constant e:
e = 1 + 1/1! + 1/2! + 1/3! + 1/4! + 1/5! + 1/6!.........
here n! means n factorial, for example 5! = 5x4x3x2x1x = 120.

I need help writing a program to do this
Oct 30 '07 #1
5 8040
Ganon11
3,652 Expert 2GB
OK, what have you done so far?
Oct 30 '07 #2
i can code a basic factorial such as the factorials from 1 to 5:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream> 
  2. using std::cout; 
  3. using std::endl; 
  4.  
  5. int main() 
  6.    int factorial; 
  7.    cout << "X\tFactorial of X\n"; 
  8.    for ( int i = 1; i <= 5; ++i ) { 
  9.       factorial = 1; 
  10.       for ( int j = 1; j <= i; ++j ) 
  11.          factorial *= j; 
  12.       cout << i << '\t' << factorial << '\n'; 
  13.    } 
  14.    cout << endl; 
  15.    return 0; 
  16. }


But i do not know how to to 1/n!
Oct 30 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
But i do not know how to to 1/n!
How does 1/n get involved in a factorial calculation?
Oct 31 '07 #4
Laharl
849 Expert 512MB
He's using the Taylor Series for e^x with x=1.

Here's a hint: 1/x is the same as x^(-1).
Nov 1 '07 #5
weaknessforcats
9,208 Expert Mod 8TB
He's using the Taylor Series for e^x with x=1.
My mistake. I thought he was calculating factorials.
Nov 1 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Mahesha | last post by:
Exponential Moving avg is calculated using the formula. EMA = (Today's Price)* K + (EMA yesterday) * (1-K) where K = 2 / (N+1) The user is going to Input the K. It is something like F(N) =...
9
by: J.Sperlhofer | last post by:
Good morning, Javascript-Professionals. I'm looking for an possibility to show a (calculated) 64bit-Number without exponential notation. I don't want to see exponational notation within my...
5
by: sugaray | last post by:
Hi, my problem with calculating the size of an array is when I pass an array as a parameter to a function which perform the calculation, the result never comes right, like below: int...
2
by: Rod Brick | last post by:
I'm trying to print a Double in straight decimal form, not exponential. I can't seem to accomplish this. This seems like it should be simple enough. The output I'm looking for is "0.00001", not...
8
by: Martin Jørgensen | last post by:
Hi, I have a program that reads in a couple of numbers from files and then stores them with some latex-code but I'm not satisfied with the exponential output, as it takes up too many character...
10
by: Lisa | last post by:
In translating the formula for calculating lottery odds for various conditions into a Visual Basic Program, I have apparently missed something in that I get errors in the part of the calculation...
2
by: Poz | last post by:
Is there a way to convert an exponential number (held in string format) to non-exponential format without losing any precision in the number? For example, I have a string variable containing...
4
by: b4ukiran | last post by:
Hi all, I have a requirement to print large double values without the exponential notaion. The double value can be a declared variable or any calculated value within the code. In any case, I...
3
ashsa
by: ashsa | last post by:
Hi everyone, I am trying to display a numeric value fetched from an sql server table which is stored in the exponential notation. For eg, 0.08 is getting stored in the table as...
1
by: pankajprakash | last post by:
Hi, I have a decimal number. I need to convert this decimal value to exponential value. I have a vb.net code to convert from decimal to exponential value is Format(100000, #.0#E-##) . When I run this...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.