Pi number In C++ Please HELPPPP!!!!!!!!!

Discussion in 'C++' started by FSMehmet, Feb 16, 2009.

  1. FSMehmet

    FSMehmet Guest

    Hi how are you???
    Hey who can help me to find the 111 digit of pi number in C++
    Pleaseeee helpppppppppp.
    FSMehmet, Feb 16, 2009
    #1
    1. Advertising

  2. FSMehmet

    Fred Guest

    On Feb 16, 11:14 am, FSMehmet <> wrote:
    > Hi how are you???
    > Hey who can help me to find the 111 digit of pi number in C++
    > Pleaseeee helpppppppppp.


    "1"

    --
    Fred
    Fred, Feb 16, 2009
    #2
    1. Advertising

  3. FSMehmet

    red floyd Guest

    FSMehmet wrote:
    > Hi how are you???
    > Hey who can help me to find the 111 digit of pi number in C++
    > Pleaseeee helpppppppppp.


    Ask your instructor.
    red floyd, Feb 16, 2009
    #3
  4. FSMehmet

    osmium Guest

    "FSMehmet" wrote:

    > Hey who can help me to find the 111 digit of pi number in C++


    There are some nice hits on google if you give it
    pi algorithm
    as a search target. But since C++ does not deal innately with numbers as
    large as 111 digits, you will need some way to attack that problem. What
    rules did your instructor give you? Can you use an existing big number
    library? Or must you write your own? Break the problem down into sub
    problems until you get to something you can actually, or potentially, do. A
    four function calculator isn't hard in C++, but the method from the google
    hits I favored required square roots too, so that might be next sub problem.
    Think Newton-Raphson.
    osmium, Feb 16, 2009
    #4
  5. FSMehmet

    mzdude Guest

    On Feb 16, 2:14 pm, FSMehmet <> wrote:
    > Hi how are you???
    > Hey who can help me to find the 111 digit of pi number in C++
    > Pleaseeee helpppppppppp.


    goto wikipedia and look up pi.

    create a small program

    const char pi[] = "314159265358979323846264338327950288419716939"
    "937510582097494459230781640628620899862803482"
    "53421170679821480865";

    char getPiDigit( int idx )
    {
    return pi[idx];
    }

    Of course this doesn't help when the requirements change to
    the 112th or greater position.

    Wikipedia also lists several good algorithms for calculating pi.

    good luck.
    mzdude, Feb 16, 2009
    #5
  6. FSMehmet

    James Kanze Guest

    On Feb 16, 8:57 pm, "osmium" <> wrote:
    > "FSMehmet" wrote:
    > > Hey who can help me to find the 111 digit of pi number in C++


    > There are some nice hits on google if you give it
    > pi algorithm
    > as a search target. But since C++ does not deal innately with numbers as
    > large as 111 digits, you will need some way to attack that problem.


    Just a nit, but that should read "[...]since most C++
    implementations don't support 111 digit numbers[...]". The
    standard requires a minimum of 10 decimal digits for double, but
    it doesn't set any maximum, so an implementation using 256 byte
    doubles would be perfectly conform. Albeit a bit slow for most
    uses on most platforms:). (FWIW: I am aware of one
    implementation of Fortran which used 256 byte floats on a
    Siemens BS2000. And yes, it was very, very slow.)

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
    James Kanze, Feb 17, 2009
    #6
  7. FSMehmet

    Daniel Pitts Guest

    FSMehmet wrote:
    > Hi how are you???
    > Hey who can help me to find the 111 digit of pi number in C++
    > Pleaseeee helpppppppppp.

    Start with 3.14159 and work from there :)

    There are plenty of algorithms to find arbitrary number of digits in PI.
    I suggest using a search engine to find the algorithms.

    If you have a particular question about why your C++ implementation of
    said algorithm isn't doing what you expect it to do, then come back and
    post.

    --
    Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
    Daniel Pitts, Feb 17, 2009
    #7
  8. FSMehmet

    Stefan Ram Guest

    FSMehmet <> writes:
    >Hey who can help me to find the 111 digit of pi number in C++


    #include <iostream>
    #include <ostream>

    int main(){ unsigned long i, j, k, n, p,
    q, x, m = 111, len = 370, pi[ 371 ];
    for( x = len; x > 0; --x )pi[ x ]= 2;
    ::std::cout << "3."; n = 0; p = 0;
    for( j = 0; j <= m; ++j )
    { q = 0; for( i = len; i > 0; --i )
    { x = 10 * pi[ i ]+ q * i;
    pi[ i ]= x %( 2 * i - 1 );
    q = x /( 2 * i - 1 ); }
    pi[ 1 ]= q % 10; q = q / 10; if( q == 9 )++n;
    else if( q == 10 ) { putchar( '1' + p );
    for( ; n; --n )::std::cout << '0'; p = 0; }
    else { if( j > 1 )::std::cout << p;
    for( ; n; --n )::std::cout << '9'; p = q; }}
    ::std::cout << p << '\n'; }
    Stefan Ram, Feb 18, 2009
    #8
  9. FSMehmet

    Guest

    On 18 Feb, 01:26, -berlin.de (Stefan Ram) wrote:
    > FSMehmet <> writes:
    > >Hey who can help me to find the 111 digit ofpinumber in C++

    >
    > #include <iostream>
    > #include <ostream>
    >
    > int main(){ unsigned long i, j, k, n, p,
    >   q, x, m = 111, len = 370,pi[ 371 ];
    >   for( x = len; x > 0; --x )pi[ x ]= 2;
    >   ::std::cout << "3."; n = 0; p = 0;
    >   for( j = 0; j <= m; ++j )
    >   { q = 0; for( i = len; i > 0; --i )
    >     { x = 10 *pi[ i ]+ q * i;
    >      pi[ i ]= x %( 2 * i - 1 );
    >       q = x /( 2 * i - 1 ); }
    >    pi[ 1 ]= q % 10; q = q / 10; if( q == 9 )++n;
    >     else if( q == 10 ) { putchar( '1' + p );
    >       for( ; n; --n )::std::cout << '0'; p = 0; }
    >     else { if( j > 1 )::std::cout << p;
    >       for( ; n; --n )::std::cout << '9'; p = q; }}
    >   ::std::cout << p << '\n'; }


    Thanksssss .. . . . . .
    , Feb 18, 2009
    #9
  10. FSMehmet

    havocjoseph Guest

    On Feb 17, 8:26 pm, -berlin.de (Stefan Ram) wrote:
    > FSMehmet <> writes:
    > >Hey who can help me to find the 111 digit of pi number in C++

    >
    > #include <iostream>
    > #include <ostream>
    >
    > int main(){ unsigned long i, j, k, n, p,
    >   q, x, m = 111, len = 370, pi[ 371 ];
    >   for( x = len; x > 0; --x )pi[ x ]= 2;
    >   ::std::cout << "3."; n = 0; p = 0;
    >   for( j = 0; j <= m; ++j )
    >   { q = 0; for( i = len; i > 0; --i )
    >     { x = 10 * pi[ i ]+ q * i;
    >       pi[ i ]= x %( 2 * i - 1 );
    >       q = x /( 2 * i - 1 ); }
    >     pi[ 1 ]= q % 10; q = q / 10; if( q == 9 )++n;
    >     else if( q == 10 ) { putchar( '1' + p );
    >       for( ; n; --n )::std::cout << '0'; p = 0; }
    >     else { if( j > 1 )::std::cout << p;
    >       for( ; n; --n )::std::cout << '9'; p = q; }}
    >   ::std::cout << p << '\n'; }


    Readability fail.
    havocjoseph, Feb 18, 2009
    #10
  11. FSMehmet

    red floyd Guest

    On Feb 18, 12:13 pm, havocjoseph <> wrote:
    > On Feb 17, 8:26 pm, -berlin.de (Stefan Ram) wrote:
    >
    >
    >
    > > FSMehmet <> writes:
    > > >Hey who can help me to find the 111 digit of pi number in C++

    >
    > > #include <iostream>
    > > #include <ostream>

    >
    > > int main(){ unsigned long i, j, k, n, p,
    > >   q, x, m = 111, len = 370, pi[ 371 ];
    > >   for( x = len; x > 0; --x )pi[ x ]= 2;
    > >   ::std::cout << "3."; n = 0; p = 0;
    > >   for( j = 0; j <= m; ++j )
    > >   { q = 0; for( i = len; i > 0; --i )
    > >     { x = 10 * pi[ i ]+ q * i;
    > >       pi[ i ]= x %( 2 * i - 1 );
    > >       q = x /( 2 * i - 1 ); }
    > >     pi[ 1 ]= q % 10; q = q / 10; if( q == 9 )++n;
    > >     else if( q == 10 ) { putchar( '1' + p );
    > >       for( ; n; --n )::std::cout << '0'; p = 0; }
    > >     else { if( j > 1 )::std::cout << p;
    > >       for( ; n; --n )::std::cout << '9'; p = q; }}
    > >   ::std::cout << p << '\n'; }

    >
    > Readability fail.


    That was the whole point. OP wanted us to do his homework for him,
    so Stefan gave him something highly obfuscated.
    red floyd, Feb 18, 2009
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    502
    Chris Uppal
    May 5, 2005
  2. KK
    Replies:
    2
    Views:
    546
    Big Brian
    Oct 14, 2003
  3. MuZZy
    Replies:
    7
    Views:
    1,740
    Mike Hewson
    Jan 7, 2005
  4. CC Fanatic

    cs1.Keyboard; HELPPPP

    CC Fanatic, Sep 14, 2008, in forum: Java
    Replies:
    0
    Views:
    576
    CC Fanatic
    Sep 14, 2008
  5. mera
    Replies:
    7
    Views:
    1,096
Loading...

Share This Page