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

F

FSMehmet

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

osmium

FSMehmet said:
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.
 
M

mzdude

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.
 
J

James Kanze

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.)
 
D

Daniel Pitts

FSMehmet said:
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.
 
S

Stefan Ram

FSMehmet said:
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'; }
 
R

r.isfendiyar

FSMehmet said:
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 .. . . . . .
 
H

havocjoseph

FSMehmet said:
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.
 
R

red floyd

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top