I'm having problem writing code for a program that estimates the value of the mathematical constant e by using this formula e= 1 + 1/1! + 1/2!...
I just cant get this to work. Can someone please help
ellas747
0
Newbie Poster
Recommended Answers
Jump to PostHmm ... start by writing a recurisve function to find the factorial of a number. There's a tutorial on recursion in either the C++ or the Computer Science section of this site - I forget which. You should also be able to find this function by doing a quick google …
Jump to Post>how do you get to calculae a power. is it pow(...)
Yes, that's one way.
Jump to Post>for ( int i = 1; i < 4000; i++ ) {
>e += 1.0 / fakt(i);
Wow, I'm impressed if you can fit up to 3999! into a double. I just get undefined behavior when the limit of double is exceeded. :rolleyes:
Jump to Post>but with my compiler the result is still correct
That's nice, but your code is still wrong even if the compiler that you use happens to interpret "undefined" as something intelligent.
Jump to PostSince this is not a for-hire service, I think it's good that we watch over each other, but code snippets should be seen as starting points or suggestions, not finished product. None of the snippets or suggestions I make are ones I've built and tested, only ideas to get the …
All 20 Replies
Dani
3,987
The Queen of DaniWeb
Administrator
Featured Poster
Premium Member
ellas747
0
Newbie Poster
ellas747
0
Newbie Poster
Narue
5,707
Bad Cop
Team Colleague
ZuK
0
Light Poster
Narue
5,707
Bad Cop
Team Colleague
ZuK
0
Light Poster
Narue
5,707
Bad Cop
Team Colleague
ZuK
0
Light Poster
Chainsaw
12
Posting Pro in Training
Narue
5,707
Bad Cop
Team Colleague
ZuK
0
Light Poster
Narue
5,707
Bad Cop
Team Colleague
ZuK
0
Light Poster
Narue
5,707
Bad Cop
Team Colleague
Dave Sinkula
2,398
long time no c
Team Colleague
Narue
5,707
Bad Cop
Team Colleague
Dave Sinkula
2,398
long time no c
Team Colleague
Chainsaw
12
Posting Pro in Training
Narue
5,707
Bad Cop
Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.