Last active
August 29, 2015 14:04
-
-
Save KodeSeeker/fd1fdc0eb25f38be8789 to your computer and use it in GitHub Desktop.
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
| public int SqRoot(int num) | |
| { | |
| if(num<0 || num>INTEGER.MAX_VALUE) | |
| throw new Exception(); | |
| int high=num; | |
| int low=0; | |
| int mid =Math.floor((low+high)/2); | |
| while(low+1<high) | |
| { | |
| if(mid*mid==num) | |
| return mid; | |
| else if (mid>num) | |
| high=mid; | |
| else | |
| low=mid; | |
| } | |
| return low;// if mid*mid never becomes num. | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment