用牛顿法写根号3的程序.
谢谢了。
static void Main(string[] args)
{
Console.WriteLine("怀珨跺婓-9999ㄛ9999善9999,9999眳潔腔淕杅");
try
{
int i = Convert.ToInt32(Console.ReadLine());
// if((i > -100000000) && (i < 100000000))
// {
// Converter(i);
// }
Console.WriteLine(sqrtn(8,3));
Console.ReadLine();
}
catch(Exception ee)
{
Console.WriteLine(ee.Message);
return;
}
}
static float sqrtn(float a,float n)
{
float xx = 1;
float sum = xx;
int i=1;
while (i<n)
{
sum=sum*xx;
i++;
}
float sum1 = sum/xx;
float f=sum-a;
float f1=n*sum1;
while (Math.Abs(f)>0.001)
{
xx = xx-f/f1;
int j = 1;
sum = xx;
while (j<n)
{
sum = sum*xx;
j++;
}
sum1 = sum/xx;
f = sum-a;
f1 = n*sum1;
}
return xx;
}