The value for PI can be determined by the series equation
PI=4x(1-1/3+1/5-1/7+1/9-1/11+1/13-....)
write an interactive program that asks the user how manu terms of series
equation to use in approximating PI. Then calculate and display the
approximation. Here is a sample run:
PI Approximation Program
How many terms of the series should be included?
(The more terms, the better the approximation)
=> 3
Approximation value of pi is 3.466667.
I hope he does, 3.4 is a tad bit off .... hey try to do the project on your own and when you get absolutley then specify your exact problem and post some code then we can help you out
you need to display pi when it has been approximated:
cout << "approximate value of pi is"<<pi<<endl;
and pi =4x(1-1/3+1/5-1/7-+1/9-1/11+1/13/...); will not work becuase the compiler can not calculate the ... so to coninue you would need some sort of looped structure. Then when it has done that, all you have to do is multiply by 4.
#include <iostream.h>
#include <math.h>
int main()
{
double pi = 0; // Calculating pi/4
int elements = 2000;
for (long int n = 1; n <= elements; n++)
{
pi += (double) pow(-1, n+1)/(2*n-1);
}
// Calculating pi
pi *= 4;
cout << "Estimated PI value (" << elements << " elements): "<< pi;
return 0;
}
As you can see I left some work in there for you, but it up to you to find out how the program works and what you need to modify to allow the user to determin the number of cycles.
you need to display pi when it has been approximated:
cout << "approximate value of pi is"<<pi<<endl;
and pi =4x(1-1/3+1/5-1/7-+1/9-1/11+1/13/...); will not work becuase the compiler can not calculate the ... so to coninue you would need some sort of looped structure. Then when it has done that, all you have to do is multiply by 4.
#include <iostream.h>
#include <math.h>
int main()
{
double pi = 0; // Calculating pi/4
int elements = 2000;
for (long int n = 1; n <= elements; n++)
{
pi += (double) pow(-1, n+1)/(2*n-1);
}
// Calculating pi
pi *= 4;
cout << "Estimated PI value (" << elements << " elements): "<< pi;
return 0;
}
As you can see I left some work in there for you, but it up to you to find out how the program works and what you need to modify to allow the user to determin the number of cycles.
I modify it the way you told me too and send ask the user how to enter info. but the program tells me that path <iostream.h> does not exist.
do you think i should not use that, i tried <isotream> i still get error.
usingnamespace std; use that with <iostream> and it should work.
when i have usingnamespace std; there already and it is stil not working? it gave me more errors than before.
it says about <math.h> i removed that too.
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.