#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; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。