x 的平方根OJ链接:69. x 的平方根 - 力扣(LeetCode)
题目:

思路:
乍一看题目只需要算一个数的平方根,根据我们之前学的C语言我们能很快的想到使用sqrt,pow这类的<math.h>库函数,但是题目要求我们不能使用,那么我们便可以使用我们的数学思想,将给的整数拆成两个一样的数相乘。
代码实现:
cpp
int mySqrt(int x)
{
long long i=1;//因为i*i可能会溢出,所以用long long
while(i*i<=x)
{
i++;
}
return i-1;//省去小数部分
}
运行结果:

