Advertisement
Guest User

Untitled

a guest
Sep 18th, 2014
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <fstream>
  4. using namespace std;
  5. double const Pi = 4 * atan(1);
  6.  
  7. int main() {
  8. double calcPi = 0;
  9. double error = 0;
  10. ofstream outfile("c:PiA.txt", ios::out);
  11. outfile << "N" << "\t" << "Approximate Value" << "\t" << "Actual Value" << "\t" << "Percent Error" << endl;
  12.  
  13. for (int k = 0; k <= 15; k++)
  14. {
  15. calcPi = calcPi + (pow(-1.0, k) * (4.0 / ((2.0 * k) + 1.0)));
  16. error = (((calcPi - Pi) * 100) / Pi);
  17. cout << "At k = " << k << ", the approximation for Pi is " << calcPi << " and the percent error is " << error << endl;
  18. outfile << k << "\t" << calcPi << "\t" "\t" "\t" << Pi << "\t" "\t" << error << endl;
  19. }
  20. return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement