LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 03-22-2004, 01:06 PM   #1
liquid sky
LQ Newbie
 
Registered: Mar 2004
Posts: 7

Rep: Reputation: 0
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???
 
Old 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: Reputation: 51
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
 
Old 03-22-2004, 01:38 PM   #3
aaa
LQ Guru
 
Registered: Jul 2003
Location: VA
Distribution: Slack 10.1
Posts: 2,194

Rep: Reputation: 47
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.
 
Old 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: Reputation: 51
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
 
Old 03-22-2004, 02:00 PM   #5
aaa
LQ Guru
 
Registered: Jul 2003
Location: VA
Distribution: Slack 10.1
Posts: 2,194

Rep: Reputation: 47
yeah, use float or double.
 
Old 03-22-2004, 02:25 PM   #6
liquid sky
LQ Newbie
 
Registered: Mar 2004
Posts: 7

Original Poster
Rep: Reputation: 0
thanks alot i was only lookin for the idea to solve it
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
which language? caminoix Programming 14 06-27-2005 04:57 PM
openoffice 1.9.79 equation editor problems salviadud Linux - Software 6 05-19-2005 04:02 AM
Transparency Equation leonidg Programming 3 02-08-2005 02:38 AM
How to create equation in Abiword ? futurist General 9 04-07-2002 12:14 PM
what language TravisB Programming 2 03-29-2002 04:39 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration