我必须编写一个程序,它接受一个数字并输出它的平方根。例如 - 45 --> 3√5。我做了一个程序,但它只返回我输入的相同数字。非常感谢帮助。这是我的代码-->
#include<iostream>
using namespace std;
int squarerootfinder(int number, int divisor){
if(divisor == 1){
return 1;
}
else{
if((number / (divisor * divisor))% 1 != 0){
divisor = squarerootfinder(number, divisor - 1);
}
if((number/ (divisor * divisor)) % 1 == 0 ){
return divisor;
}
}
}
int main(){
int number;
cout << "Enter a number to find the square root of it \n";
cin >> number;
int divisor = number;
int squareroot;
squareroot = squarerootfinder(number, divisor);
cout << squareroot << endl;
return 0;
}