Hello,

Recently I came across this interview question:

Find the square root of a number without using any inbuilt function.

Here is my code for it:

```
sqrt_1 <- function(n){
for (i in 1:n-1){
r <- i * i
if (r <= n) x = i
}
x
}
```

But this is good only for squares like 25,36 etc.For others it gives the previous square root.

```
> sqrt_1(9.1)
[1] 3
```

I learned that this is a basic interview question which has been asked in many interviews:

stackoverflow.Though this link gives many ways to calculate this in other languages I am looking for a solution in R.

Can someone please help me with this one?