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

1. ### FSMehmetGuest

Hi how are you???
Hey who can help me to find the 111 digit of pi number in C++

FSMehmet, Feb 16, 2009

2. ### FredGuest

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++

"1"

--
Fred

Fred, Feb 16, 2009

3. ### red floydGuest

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

red floyd, Feb 16, 2009
4. ### osmiumGuest

"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
5. ### mzdudeGuest

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++

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
6. ### James KanzeGuest

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
7. ### Daniel PittsGuest

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

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
8. ### Stefan RamGuest

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
9. ### 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
10. ### havocjosephGuest

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'; }

havocjoseph, Feb 18, 2009
11. ### red floydGuest

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'; }

>