#define _USE_MATH_DEFINES #include <math.h> #include <iostream> #include <iomanip> /** * Estimate PI using Leibiniz series * 1 - (1/3) + (1/5) - (1/7) + (1/9) .... = (pi / 4) */ void calc(int terms) { long double pi = M_PI; long double sum = 0; long long int denom = 1; for(int i = 0; i < terms; i++) { sum += pow(-1, i) * ( 1 / double(denom) ); denom += 2; long double estimate = sum * 4; long double diff = abs(pi - estimate); std::cout ...
Articles
First Article
106 views