A
Arash_89
Guest
Hello,
We have Precision in result when we don't use parenthesis.
We don't have precision in result when we use parentheses.
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...
We have Precision in result when we don't use parenthesis.
We don't have precision in result when we use parentheses.
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...