求大数平方根

#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("%.0f\n", floor(sqrt(value))); 
	}
	return 0;
}


 

 

下面是迭代方法:

#include<iostream>
using namespace std;
void main()
{
	__int64 num=0xffffffffffffffff;
	printf("%I64d\n",num);
}
#include<iostream>
#include<math.h>
using namespace std;	
void main()
{
	__int64 num;
	__int64 result;
	num=0xff;
	result=sqrt();
	printf("%I64d\n",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;  
 } 


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值