-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSquare root.cpp
53 lines (47 loc) · 1.08 KB
/
Square root.cpp
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
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
Given an integer x , Your task is to find the square root of it. If x is not a perfect square, then return floor(vx)
Input:
You have to complete the method which takes 1 argument: the integer N. You should not read any input from stdin/console. There are multiple test cases. For each test cases, this method will be called individually.
Output:
Your function should return square root of given integer.
Constraints:
1 = T = 1000
1 = N = 1000000
Example:
Input
2
5
4
Output
2
2
SUMIT KUMAR */
#include<bits/stdc++.h>
using namespace std;
long long int floorSqrt(long long int x);
int main()
{
int t;
cin>>t;
while(t--)
{
long long n;
cin>>n;
cout << floorSqrt(n) << endl;
}
return 0;
}
/*Please note that it's Function problem i.e.
you need to write your solution in the form of Function(s) only.
Driver Code to call/invoke your function is mentioned above.*/
/*You are required to complete
this function*/
long long int floorSqrt(long long int x)
{
int s=1;
while(s*s<=x)
{
s++;
}
return s-1;
}