fork(1) download
  1. #include<iostream>
  2. using namespace std;
  3. int main(){
  4. // Find the sqr root of the number
  5. cout<<"Enter the number\n";
  6. int num1;
  7. cin>>num1;
  8. int num=num1;
  9. int start=0;
  10. int sqrts;
  11. while(start<=num){
  12.  
  13. int mid=start+(num-start)/2;
  14. if(mid*mid==num){
  15. sqrts=mid;
  16. return 0;
  17. }else if(mid*mid<num){
  18. sqrts=mid;
  19. start=mid+1;
  20. }else{
  21. num=mid-1;
  22. }
  23. }
  24. cout<<sqrts;
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0.01s 5280KB
stdin
80
stdout
Enter the number
1