Precision in C# without Parenthesis

  • Thread starter Thread starter Arash_89
  • Start date Start date
A

Arash_89

Guest
Hello,


We have Precision in result when we don't use parenthesis.

1497255.jpg


We don't have precision in result when we use parentheses.


1497256.jpg





In two cases we have divided an integer by double (1/fraction) but we have different result.


static void Main(string[] args)
{
Console.WriteLine("Number??");
int number = Int32.Parse(Console.ReadLine());
double sum = 0;
for (int i = 1; i <= number; i++)
{
sum += 1.0 / (Math.Sqrt(i) + Math.Sqrt(i + 1)); // and sum += 1.0 / Math.Sqrt(i) + Math.Sqrt(i + 1);
}
Console.WriteLine(sum);

}

Continue reading...
 
Back
Top