#include #include #include //for setprecision using namespace std; template T pi() { T pi_val = 0; T sign = 1; const long n = 1000000; for (long i = 1; i < n; i += 2) { pi_val += sign / i; sign = -sign; } pi_val += sign / (2 * n); return 4 * pi_val; } int main() { cout << setprecision(19) << "float " << pi() << "\n" << "double " << pi() << "\n" << "long double " << pi() << "\n"; return EXIT_SUCCESS; }