Created
August 6, 2015 21:22
-
-
Save viveksyngh/e0872ad3863a265eb4fe to your computer and use it in GitHub Desktop.
Finds SQRT of an integer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| __author__ = 'Vivek' | |
| #Find Square root of an inetger , if Square root is not integer returns floor of sqrt | |
| def sqrt(A) : | |
| if 2 > A : | |
| return A | |
| low = 0 | |
| high = A | |
| while high > low + 1 : | |
| num = (low + high)/2 | |
| if num**2 < A : | |
| low = num | |
| elif num**2 > A : | |
| high = num | |
| else : | |
| break | |
| if A == num**2: | |
| return num | |
| else : | |
| return low | |
| print(sqrt(25)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment