121
votes
Help!! How to do square root!
Java
Wow, this is a complicated problem. I've never done a square root before. I've taken square roots, but I haven't done one. Don't forget to make your code look pretty for extra credit in your ...
71
votes
Help!! How to do square root!
C++
Well, if you've got no better route, there's always the brute-force solution:
...
64
votes
Help!! How to do square root!
Python 3
This simple code will give an exact answer:
x = input('Enter a number: ')
print('\u221A{}'.format(x))
45
votes
Help!! How to do square root!
In Python 3 you can do the following:
def square_root(n):
return float(n)**0.5
42
votes
Help!! How to do square root!
Correcting this answer,
Using C, because C is fastest
That's just plain wrong. Everyone knows that the fastest one is ASM.
Pure x86_64 ASM!
...
39
votes
Help!! How to do square root!
Python
Write a function or program that will "make a number square root".
If it's allowed in your class you can use a complex mathematics library as a helper here, install it by running the ...
33
votes
Help!! How to do square root!
C
Obviously this is the best way. It's as fast as you can imagine by looking at the code. Using C, because C is fastest, and this problem requires a fast solution. I've tested this for my favorite ...
30
votes
29
votes
Help!! How to do square root!
Python 3
You guys are doing it all wrong. Anyone can see that square root of 20 is not 4.47213595499958, or even √20. This solution moves the difficult task of calculating the square root to the ...
28
votes
Help!! How to do square root!
JavaScript
Unfortunately, JavaScript does not support the square root symbol for function names. Instead, we can use some other Unicode alphabet character to represent a square root function.
In ...
25
votes
Help!! How to do square root!
Julia
Obviously the best way to do it, its using the squared root Taylor Series:
...
20
votes
Help!! How to do square root!
Haskell
I stopped trusting computers when I first heard about floating-point errors. I mean, seriously, if even Google can't get them under control, then who can?
So our best bet is to find a ...
20
votes
Help!! How to do square root!
LaTeX
The solution for this is pretty hard and very complex, so take your coffee. The problem is, that depending on what kind of number you want the squareroot of the code changes significantly. I'll ...
16
votes
Help!! How to do square root!
Java
The most precise way to do this is to iterate. First, loop by integers until you go over the target, then switch over to ...
11
votes
Help!! How to do square root!
Javascript
These magic constants can be used to compute the square root of a number using the alphabet:
...
10
votes
Help!! How to do square root!
JavaScript/ActionScript
There is no way to directly calculate a square root in either ActionScript or JavaScript, however, there is a workaround. You can get the square root of a number by raising it ...
10
votes
Help!! How to do square root!
JavaScript
Very difficult problem !
There is no built-in function for that in JavaScript...
Looks like a job for the Newton-Raphson solver.
...
9
votes
Help!! How to do square root!
PHP (and others):
Since the way that was described the question didn't meant that we actually need to calculate it, here is my solution:
...
9
votes
Help!! How to do square root!
Python 2.7
n = input("Enter a number which you want to make a square root: ")
print "\u221A{} = {}".format(n**2, n)
Explanation
Quoting
Wikipedia - Square ...
8
votes
Help!! How to do square root!
C++
based on http://en.wikipedia.org/wiki/Fast_inverse_square_root and @snack's answer.
Except instead of bolting on a way to convert the x^(-0.5) into x^(0.5) I modified the algorithm to do it ...
8
votes
Help!! How to do square root!
C
This is better than all other 27 answers because those are all inaccurate. That's right, they only give one answer when there should be 2. This one doesn't even try to answer if it's going to be ...
7
votes
Help!! How to do square root!
E
Note: this only works on my computer, as the underlying hardware does not store numbers in binary but in base e, such that what appears as 10 represents e, ...
6
votes
Help!! How to do square root!
JavaScript/HTML/CSS
I thought about using jQuery and ids to troll a bit more, but I prefer vanilla js.
The result is not perfectly precise, but it works !
...
6
votes
Help!! How to do square root!
GeoGebra
a=4
input=InputBox[a]
A=(a,0)
B=(-1,0)
Answer=Intersect[Semicircle[B,A],yAxis]
ShowLabel[Answer,true]
Read off the value of your answer from the ...
6
votes
Help!! How to do square root!
100% pure bash (integer based)
With ascii-art presentation:
This perfect root square have to be sourced in bash by using source command
...
4
votes
Help!! How to do square root!
Java
Thanks, to ggmx's for code on generating n digits of pi in java.
...
3
votes
Help!! How to do square root!
JQuery
this one is the most accurate (bonus: also works for letters!)
Please enter the number :
...
3
votes
3
votes
Help!! How to do square root!
Python
This solution:
is non deterministic and yields approximate answers
is O(N) and quite slow, even for low N
relies on an obscure mathematical relationship
Spoiler:
Code:
...
3
votes
Help!! How to do square root!
C++
Your question don't compile because you put a ! at the end. C++ don't like !Here the correct question for the compiler:
...
Only top scored, non community-wiki answers of a minimum length are eligible