Here's the problem:
Calculate the value of pi from the infinite series
pi = 4 - (4/3) + (4/5) -(4/7) + (4/9) - (4/11) + ...
Print a table that shows the value of pi approximated by computing one term of this series, by two terms, by three terms, and so on. How many terms of this series do you have to use before you first get 3.14 3.141 3.1415 3.14159 Here is the code I have so far:
using
System;public
class Pi{
// Main method begins execution of C# application public static void Main(string[] args){
double pi = 4; for (int n = 1; n <= 100; n+=4){
pi = pi - (4 / (n + 2)) + (4 / (n + 4));
Console.WriteLine("{0,4}", pi);}
}
// end method Main}
// end class Pi
When I execute the code all I get is a line of 3s. Where is my math wrong