Answer to Question #26316 in C++ for kassem
I want to write a program to calculate Pi:Pi=4-4/3+4/5-4/7+4/9-4/11+...(the user inputs the number of terms in the series)
1
2013-03-14T10:42:07-0400
#include <iostream>
using namespace std;
double calc_PI(int termCount)
{
double result = 0.0;
double divider = 1;
char sign = 1;
while (termCount--)
{
result += (4 * sign / divider);
divider += 2;
sign = -sign;
}
return result;
}
int main()
{
int termCount;
cout << "Enter the number of series: ";
cin >> termCount;
cout << "PI = " << calc_PI(termCount);
return 0;
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
C++
Comments
Leave a comment