Thread: programing with pi, canīt get it

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    6

    Arrow programing with pi, canīt get it

    Hi guys, I have the next program as assignment, but because english is not my first language, i just canīt get what it really wants me to do, could any of you explain it to me in a simplier way please?

    The number π, or 3.1415..., can be calculated from the infinite series
    π = 4 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11 ...
    Query the user for the number of terms to use in the approximation, and then calculate π. Then ask if they wish to repeat using a different number of terms. Indicate in your email the approximate number of iterations required to calculate π to six decimal places. Use double instead of float for extra precision.

    Hint: This lab is easy to solve if you store the numerator and denominator in separate variables.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Your assignment wants you to use a loop and the series it gave you, to calculate pi.

    The good tip is to keep the numerator (top number of the fraction), in a separate variable from the bottom number of the fraction.

    You may want to put the real Pi number, into a string, and then you can count (inside your outer loop), the number of digits of resolution you have calculated, that matches up with the real Pi digit:

    Code:
    Pistr[]="3.14159265358979"; //you may need more digits
    
    Now put your currently calculated number into a string of your own, and compare it, char by char
    
    while(Pistr[i] == myPi[i++] );
    
    --i; //backtrack one time
    Your calculation is correct to i digits. When i equals the number of digits of resolution you need, your program is done, so this is the stop condition for your outer loop (while or for).

    what you need to do is to get started and post up what you have done, and what has you stumped atm.

    Then we can be more helpful.
    Last edited by Adak; 02-12-2011 at 05:03 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pi - Hm, somethign is not right here.
    By MadnessRed in forum C++ Programming
    Replies: 8
    Last Post: 09-12-2008, 01:07 PM
  2. PI Equation in C
    By wallysworld in forum C Programming
    Replies: 13
    Last Post: 10-23-2006, 08:12 PM
  3. Pi Calculation
    By EvilGuru in forum C Programming
    Replies: 2
    Last Post: 05-02-2005, 04:25 AM
  4. Pi and the standard library
    By FOOTOO in forum C Programming
    Replies: 7
    Last Post: 04-15-2005, 11:23 AM
  5. C for PI
    By Lynux-Penguin in forum C Programming
    Replies: 13
    Last Post: 04-28-2002, 07:37 PM