0

Write a program to find squre root ?

Without using sqrt() in python

5th May 2019, 8:18 PM
Redwine🍷🍻
Redwine🍷🍻 - avatar
7 odpowiedzi
+ 6
A root of a number is just x**(1÷2), where x is the number you want to find the square root of, so using that would return the same thing as sqrt(x)
5th May 2019, 9:43 PM
Faisal
Faisal - avatar
+ 6
C, C++ do have a function called pow defined in the math library. For others you can write an exp function to do the same. Exponentiation being iterated multiplication. 2^3 = 2*2*2 For (n^m) Using a for loop which runs m times and multiplies n by a result variable(r=1). #Demo code in ruby https://code.sololearn.com/cMxG18sTH9wb/?ref=app
6th May 2019, 1:53 AM
Lord Krishna
Lord Krishna - avatar
+ 5
Here is a tutorial which explains newton's method: https://youtu.be/2158QbsunA8
5th May 2019, 8:28 PM
Denise Roßberg
Denise Roßberg - avatar
+ 4
Werg Serium I don't know, but he can ask us if not. I think Faisals method is much easier ;)
5th May 2019, 9:48 PM
Denise Roßberg
Denise Roßberg - avatar
0
Denise the question is, can he put the newton's method into code?
5th May 2019, 9:16 PM
Werg Serium
Werg Serium - avatar
0
Yes it is Denise. The Faisal method is the simplest ones. No need of hard maths xD
5th May 2019, 10:36 PM
Werg Serium
Werg Serium - avatar
0
But this is only possible because in python there is an exponential operator **. If you try java, c or c++, there is no way if you did not use newton's method.
5th May 2019, 11:05 PM
Werg Serium
Werg Serium - avatar