求2的开方精确到1000位以上的算法

来源:百度知道 编辑:UC知道 时间:2024/05/29 09:11:37
精确到1000位以上的算法

用二分法求2的平方根

//这是用java编写的一个求2的平方根的程序,精确度可通过修改weishu参数来改变
public class app
{ //用二分法求2的平方根
public static void main(String args[])
{
int a[],b[],s[],d[],c[],ss[];
int i,j,k;
a=new int[1000];
b=new int[1000];
s=new int[1000];
d=new int[1000];
c=new int[1000];
ss=new int[1000];
boolean jingque;
jingque=true;
a[0]=b[0]=2;
a[2]=b[2]=1;
a[1]=4;
b[1]=5;

int weishu=200;//定义循环次数
for(i=0;i<1000;i++)
s[i]=0;
for(k=0;k<weishu;k++)
{
hanshucheng.cheng(b,b,s);
j=s[0];
while (s[j]>=2)
{
hanshuadd.add(a,b,c);
hanshuchu.chu(d,c);
hanshucopy.copy(ss,b);
hanshucopy.copy(b,d);
hanshucheng.cheng(b,b,s);
j