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 ...
user avatar
  • 20.9k
71 votes

Help!! How to do square root!

C++ Well, if you've got no better route, there's always the brute-force solution: ...
user avatar
  • 33.8k
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))
user avatar
  • 6,511
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
user avatar
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! ...
user avatar
  • 9,472
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 ...
user avatar
  • 511
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 ...
user avatar
30 votes

Help!! How to do square root!

C Tricks and magics will make it work. ...
user avatar
  • 2,172
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 ...
user avatar
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 ...
user avatar
  • 4,940
25 votes

Help!! How to do square root!

Julia Obviously the best way to do it, its using the squared root Taylor Series: ...
user avatar
  • 642
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 ...
user avatar
  • 7,801
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 ...
user avatar
  • 578
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 ...
user avatar
  • 19.6k
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: ...
user avatar
  • 266
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 ...
user avatar
  • 1,178
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. ...
user avatar
  • 12.1k
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: ...
user avatar
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 ...
user avatar
  • 2,911
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 ...
user avatar
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 ...
user avatar
  • 181
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, ...
user avatar
  • 245
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 ! ...
user avatar
  • 1,312
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 ...
user avatar
  • 8,956
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 ...
user avatar
  • 2,924
4 votes

Help!! How to do square root!

Java Thanks, to ggmx's for code on generating n digits of pi in java. ...
user avatar
3 votes

Help!! How to do square root!

JQuery this one is the most accurate (bonus: also works for letters!) Please enter the number : ...
user avatar
  • 2,008
3 votes

Help!! How to do square root!

C++ This will eventually get you a square root. ...
user avatar
  • 1,253
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: ...
user avatar
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: ...
user avatar
  • 1,157

Only top scored, non community-wiki answers of a minimum length are eligible