Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <fstream>
- using namespace std;
- double const Pi = 4 * atan(1);
- int main() {
- double calcPi = 0;
- double error = 0;
- ofstream outfile("c:PiA.txt", ios::out);
- outfile << "N" << "\t" << "Approximate Value" << "\t" << "Actual Value" << "\t" << "Percent Error" << endl;
- for (int k = 0; k <= 15; k++)
- {
- calcPi = calcPi + (pow(-1.0, k) * (4.0 / ((2.0 * k) + 1.0)));
- error = (((calcPi - Pi) * 100) / Pi);
- cout << "At k = " << k << ", the approximation for Pi is " << calcPi << " and the percent error is " << error << endl;
- outfile << k << "\t" "\t" << calcPi << "\t""\t" << Pi << "\t""\t" << error << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement