-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinding_square.cpp
More file actions
40 lines (38 loc) · 824 Bytes
/
Copy pathfinding_square.cpp
File metadata and controls
40 lines (38 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <bits/stdc++.h>
using namespace std;
double morepresion(int a , int precision, int result){
double factor = 1;
double ans= result;
for(int i=0;i<precision;i++){
factor= factor/10;
for(double j=ans;j*j<a;j=j+factor){
ans=j;
}
}
return ans;
}
int search_square(int a){
int start=0, end=a;
int mid= start+ (end- start)/2;
while(end>=start){
if(mid*mid>a){
end= mid-1;
}
else if(mid* mid<a){
start= mid+1;
}
else if( mid* mid == a ) {
return mid;
}
mid= start +(end-start)/2;
}
return end;
}
int main(){
int n;
cout<<"Enter the number whosea root to be find"<<endl;
cin >>n;
int result = search_square(n);
cout<< "result is "<<morepresion(n,3,result);
return 0;
}