#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; }