3.41PI C++ PrOgram

I have made a c++ program to calculate the value of pi using conitnued simple fractions: http://mathworld.wolfram.com/PiContinuedFraction.html

Here is the (Turbo Compiler) code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<iomanip.h>
#include<conio.h>
#include<iostream.h>

void main()
{
 clrscr();

 int n, A[1000]={3, 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2};
 long double pi=2;

 cout<<"Set Precision: "; cin>>n;

 for(int i=n-1;i>=0;i--)
 {
  if(i>=17)
  {
   pi=2+1/pi;
  }
  else
   pi=A[i]+1/pi;
 }

 cout<<setprecision(n+1);
 cout<<"\n\n\t!! "<<pi;
getch();
}


The only problem is in setprecision(n+1);

It does not accept large values, i.e. more than 15. If i could get precision upto 1000, that would be good.

Although, i could store the decimals in batches of 10 in long double A[1000], but im unable to form a code for that. Thanx for any help!

The only problem is in setprecision(n+1);


I disagree.

Problem:

1
2
3
#include<iomanip.h>
#include<conio.h>
#include<iostream.h> 


Problem:

 
void main()


Problem:

 
cout


Im sorry?

There is not problem in cout<<

and no problem in the #include at all!

and what problem could be in void main()??

As i said, its a Turbo Compiler Code, not a dev cpp code or any of its likes.
It's not C++. That's the problem. This is a C++ forum, not "things that were called C++ in the last millenium"-forum.

Turbo C++ is from like, 1992 or so, before the first C++ standard came out. Unless you're in some DOS-enthusiast community there is no reason to use it nowadays.
in any case why not use: PI=atan(1)*4;
Last edited on
Topic archived. No new replies allowed.