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