Back to Problem Solutions forum
Hello, i have some problems with approximation on C#.
This is my answer:
31,0484224628371
9,66240764322412
477,247238710418
24,7394736842105
5,91607978309962
9010,24985430138
1538,24983737193
116,094519508056
51,0983210255662
69,9142331717941
30,2654919008431
338,788596046481
This is expected answer: 31.0484224628 9.66240764322 477.24723871 24.7394736842 5.9160797831 9010.2498543 1538.24983737 116.094519508 51.0983210256 69.9142331718 30.2654919008 338.788596046
I had differents in the 5 element, in the 9 element and in the 10 element but your approximation not so exact. I tried to use Math.Round, but still i had mistakes. How can i solve this problem? Algorithm is right. Probably.
Thank you and sorry for my English!
Code:
static private double GeroneMethod(string[] numbers)
{
double r = 1;
double x = double.Parse(numbers[0]);
int iteration = int.Parse(numbers[1]);
for (int i = 0; i < iteration; i++)
{
r = (r + x / r)/2;
}
return r;
}
Did you try with higher precision type. ie. Decimal instead of Double ?
I don't do C#, and this comment may not help, but the most obvious difference between your answer and the expected answer, is that your answer contains commas ',' while the expected answer contains points '.'
Quandray, thank u! It was right decision! Sorry for my inadvertency.