# Issue

This Content is from Stack Overflow. Question asked by Andreas Steffensen

I needed a square root approximation in C so i looked this post: Squareroot approximation (C) . and got this following implementation:

``````float x = n;
float y = 1;
float e = 0.001; // Accuracy level
if (n == 0)
return 0;
while ((x - y) > e)
{
x = (x + y) / 2;
if (n == 0 || x == 0)
return 0;
y = n / x;
}
return x;
``````

Can anyone help me find the time complexity of this.
And if i have to much strain on the processor?

# Solution

declare x first to use it inside main function

``````float x;
``````

Like this with in the scope or you can declare globally

``````int main(){
float x;
printf("\nsquare root test 1: enter a number\n");
scanf("%f",&x);
printf("root(%.2f) = %.4f\n", x, squareRoot(x, .001));

getchar();
return 0;
}
``````

``` This Question was asked in  StackOverflow by  user2175838 and Answered by Civa It is licensed under the terms of
CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.```
people found this article helpful. What about you?