63 179
Assignments Done
99,3%
Successfully Done
In July 2018

Answer to Question #21892 in C# for abdi ahmed

Question #21892
calculate pi using the series
pi /4 =1-1/3+1/5-1/7+1/9- ... and so on.
output the estimate of pi after computing 100,1000,10,000 and 100,000 terms of the series.
Expert's answer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Calculate_pi
{
class Program
{
static void Main(string[] args)
{

Console.WriteLine("Pi after computing 100 = " + computePi(100));
Console.WriteLine("Pi after computing 1000 = " + computePi(1000));
Console.WriteLine("Pi after computing 10000 = " + computePi(10000));
Console.WriteLine("Pi after computing 100000 = " +
computePi(100000));
Console.ReadLine();
}

private static double computePi(int n)
{
double sequenceFormula = 0;
for (int counter = 1; counter < n; counter += 2)
{
sequenceFormula = sequenceFormula + ((1.0 / (2.0 * counter - 1)) - (1.0 / (2.0
* counter + 1)));
}
double pi = 4 * sequenceFormula;
return pi;
}
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions