加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

求大数平方根

发布时间:2020-12-14 04:12:10 所属栏目:大数据 来源:网络整理
导读:#include stdio.h#include string.h#include math.h//8const double EPS = 1e-3;int main(void){freopen("b.txt","r",stdin);char str[35];while( scanf("%s",str),strcmp(str,"0") )//不能直接输入double型变量,不然一定会出错{double value = 0.0,power =
#include <stdio.h>
#include <string.h>
#include <math.h>

//8const double EPS = 1e-3;

int main(void)
{
	freopen("b.txt","r",stdin);
	char str[35];
	while( scanf("%s",str),strcmp(str,"0") )//不能直接输入double型变量,不然一定会出错
	{
		double      value = 0.0,power = 1.0;
		
		for( int i=strlen(str)-1; i >= 0; --i )
		{
			value += (str[i]-'0')*power; //用pow()可能会导致精度出问题!
			power *= 10;
		}      
		printf("%.0fn",floor(sqrt(value))); 
	}
	return 0;
}


?

?

下面是迭代方法:

#include<iostream>
using namespace std;
void main()
{
	__int64 num=0xffffffffffffffff;
	printf("%I64dn",num);
}
#include<iostream>
#include<math.h>
using namespace std;	
void main()
{
	__int64 num;
	__int64 result;
	num=0xff;
	result=sqrt();
	printf("%I64dn",result);
}

#include   <iostream.h>  
void   main()  
{  
	__int64   a=0xffffffffffffff;  
	double   x[20];  
	x[0]=1;  
	for   (int   i=0;i<20;i++)  
	{  
		x[i+1]=(x[i]+(a/x[i]))/2;  
	}  
	cout   <<   x[20]   <<endl;  
 } 

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读