![]() |
| ||
| Anyway can help me to solve this problem??? What is the code for ( e^x = 1 + x/1! + x^2/2! + x^3/3! + ..... ) anyway can help me, plzzz :cry: :rolleyes: |
| ||
| Re: Anyway can help me to solve this problem??? Use a 'for' loop. Show what you think works, and tell us exactly what each line does and why. In doing this, you'll probably solve your problem, but if that fails, you'll have people here willing to help you. |
| ||
| Re: Anyway can help me to solve this problem??? Are you trying to just get the natural exponential of a number? There's a function in math library, if I'm not wrong. Try to see if the math.h of your compiler has a double exp (double) function. See http://unixhelp.ed.ac.uk/CGI/man-cgi?exp+3 For microsoft, the function prototype may be different: http://msdn.microsoft.com/library/de...larray_exp.asp |
| ||
| Re: Anyway can help me to solve this problem??? thanks for replyiing me, But i wanna write the code for (e^x = 1 + x/1! + x^2/2! + x^3/3! + ..... ) without using math library. |
| ||
| Re: Anyway can help me to solve this problem??? #include<iostream.H><< moderator edit: added code tags: [code][/code] >> The Bold font is the factorial part & its not working well, i need to fix tht, plz help (i dont wanna use any function)[I][U] |
| ||
| Re: Anyway can help me to solve this problem??? I think you know how to take a factorial of a number, but your variable usage is not good. while ( z != 0) Now, honestly, that works if you first set z to the value of whatever you want to take the factorial of, and set result to one. You're setting z equal to one before the for loop, and then incrementing it at the end of each loop, but you decrement it to zero before that, so your while loop is *entirely pointless*. Just multiply result by i, you don't need a while/for loop or whatever. -Fredric |
| ||
| Re: Anyway can help me to solve this problem??? #include<iostream.H><< moderator edit: added [code][/code] tags >> You mean like this??? :?: |
| ||
| Re: Anyway can help me to solve this problem??? I didn't see it the first time, but the ^ doesn't do what you think it does in C++, if you want to take m to the n power then you use the pow function like so... #include <math.h> That would return 2 to the 3rd, or 8. Hope that helps a bit. -Fredric |
| ||
| Re: Anyway can help me to solve this problem??? Hi, I have some issues with your variable names. result is actually not the result, and e is actually the natural log constant in your comments. Made some changes to the var and trying to do away with the pow fn. Not sure if you want to restrict your input to just integral values, but output will most definitely be double? int main() I've not tried the code, but should be ok ... |
| All times are GMT -4. The time now is 4:33 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC