Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,234 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,685 people online right now. Registration is fast and FREE... Join Now!




implementation

 
Reply to this topicStart new topic

implementation, c++

prebz
15 Mar, 2007 - 03:21 AM
Post #1

New D.I.C Head
*

Joined: 15 Mar, 2007
Posts: 1


My Contributions
an aproximate value of pi can be calculated using the series given below

Pi = 4[ 1-1/3+1/5-1/7+1/9...+((-1)powerof n )2n+1]

Write a c++ program to calculatethe approximate value of pi using this series.The program takes an input n that that determines the number of terms in the approximation of the value pf pi and outputs the approximation .Includes a loop that allows the user top repeat this calculation for new values n until the user says she or he wants to end the program.
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Implementation
15 Mar, 2007 - 03:38 AM
Post #2

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,859



Thanked: 50 times
Dream Kudos: 550
My Contributions
read the rules... we need to see some good-faith code to show that you have tried to solve the problem.

The program is a basic loop, you even have the formula (though I think it has a mistake in it ((-1)^n)/(2n+1) ). just make a for-loop to sum up the inner terms, then multiply that sum by 4...
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: Implementation
16 Mar, 2007 - 10:19 PM
Post #3

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 3,914



Thanked: 34 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
And don't iterate too many times.
At a particular point, the result is out of range for float and double data types.
This results in incorrect answers.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 03:54PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month