#include #include //for setw and setprecision #include using namespace std; int main() { double sum {0.0}; //gets closer and closer to pi double sign {1.0}; //alternates between 1.0 and -1.0 double denominator {1.0}; //grows by 2.0 during each loop for (int i {1}; i <= 1000; ++i) { //means sum = sum + sign * 4.0 / denominator sum += sign * 4.0 / denominator; cout << setw(4) << i << " " //3 spaces between the columns << fixed << setprecision(5) << sum << "\n"; sign = -sign; denominator += 2.0; //means denominator = denominator + 2.0 } return EXIT_SUCCESS; }