Last active
May 10, 2020 18:48
-
-
Save geektutor/159a1cd747aebe61b1b959c451091f70 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
void main() { | |
print(is_perfect_square(100)); | |
} | |
is_perfect_square(int number) { | |
int square = 0; | |
double iterator = 1 + (number / 4); | |
// Use iterator to check for the case of 1 * 1 is 1 | |
if (number < 5) { | |
iterator = 1 + (number / 2); | |
} | |
for (var i = 0; i < iterator; i++) { | |
if (i * i == number) { | |
square = 1; | |
break; | |
} | |
} | |
if (square == 1) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
/* | |
* | |
Day 10: Perfect Square | |
Create a function is_perfect_square that takes a parameter number and checks if the number is a perfect square. It should return True if the number is a perfect square and False if otherwise. | |
Sample Inputs | |
1) is_perfect_square(9) | |
2) is_perfect_square(100) | |
3) is_perfect_square(225) | |
4) is_perfect_square(500) | |
Sample Output | |
1) True2) True3) True4) False | |
NB: The in built square root and raised to power operator should not be used. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment