Visit Jeremy's Blog.
 LinuxQuestions.org an equation in c language
 Programming This forum is for all programming questions. The question does not have to be directly related to Linux and any language is fair game.

 03-22-2004, 01:06 PM #1 liquid sky LQ Newbie   Registered: Mar 2004 Posts: 7 Rep: an equation in c language hi I wish if there is any body that can help me i need to program a simple C program that estimates the value of e e=1+1/1!+1/2!+1/3!.........etc. any body can help me???
 03-22-2004, 01:37 PM #2 kev82 Senior Member   Registered: Apr 2003 Location: Lancaster, England Distribution: Debian Etch, OS X 10.4 Posts: 1,263 Rep: this sounds a bit like a homework question... if thats the case then accuracy isnt of a great concern, the most obvious solution is to use the formula you state above, sum the value of 1/(n!) as n goes from 0 to a high number. this is quite simple to implement in a for loop but i'll leave it fot you to have a go at cos i dont wanna give away answers to homework if you need more help post back
 03-22-2004, 01:38 PM #3 aaa LQ Guru   Registered: Jul 2003 Location: VA Distribution: Slack 10.1 Posts: 2,194 Rep: a for-loop with a factorial algorithim Code: ```int e; for(int i=0;i<=[number of terms you want to go up to];i++) e += (1 / factorial(i));``` Make the factorial function yourself. Last edited by aaa; 03-22-2004 at 01:40 PM.
 03-22-2004, 01:45 PM #4 kev82 Senior Member   Registered: Apr 2003 Location: Lancaster, England Distribution: Debian Etch, OS X 10.4 Posts: 1,263 Rep: aaa - you might want to use a different type than int for e, also declaring i inside the for loop is not valid in C
 03-22-2004, 02:00 PM #5 aaa LQ Guru   Registered: Jul 2003 Location: VA Distribution: Slack 10.1 Posts: 2,194 Rep: yeah, use float or double.
 03-22-2004, 02:25 PM #6 liquid sky LQ Newbie   Registered: Mar 2004 Posts: 7 Original Poster Rep: thanks alot i was only lookin for the idea to solve it

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is Off HTML code is Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post caminoix Programming 14 06-27-2005 04:57 PM salviadud Linux - Software 6 05-19-2005 04:02 AM leonidg Programming 3 02-08-2005 02:38 AM futurist General 9 04-07-2002 12:14 PM TravisB Programming 2 03-29-2002 04:39 PM

LinuxQuestions.org

All times are GMT -5. The time now is 11:31 AM.

 Contact Us - Advertising Info - Rules - Privacy - LQ Merchandise - Donations - Contributing Member - LQ Sitemap -