+ 18
๐๐๐๐CHALLENGE ๐๐๐๐
Write a program to check whether a number is Sunny number or not. A number n is said to be sunny number if square root of(n+1) is an integer. e.g. 8 is a sunny number because sq.root of (8+1)is 3 ,which is an integer.
20 Answers
+ 18
(Math.sqrt(n+1)%1.0==0.0)
//bcz Integer%1 will be 0 only โบ
+ 16
const isSunny = n => Math.sqrt(n+1) === parseInt(Math.sqrt(n+1)) ? true : false;
+ 13
+ 13
+ 12
https://code.sololearn.com/cRhs7z3sIdj2/?ref=app
๐๐
+ 12
Check that if you want:
https://www.sololearn.com/discuss/1150756/?ref=app
+ 12
+ 11
yes I will do that
+ 10
Remember that you can submit this as an assignment using Lesson Factory. :>
+ 9
+ 9
+ 8
+ 6
https://code.sololearn.com/cVYBCM2qxIQF/#py
Also prints out all the Sunny numbers between 0 to 100
#python
+ 6
C#
Func<int, bool> IsSunny = i => (Math.Sqrt(i + 1) == Convert.ToInt32(Math.Sqrt(i + 1))) ? true : false;
+ 4
This is my solution in java: https://code.sololearn.com/c6tlpWzXr9le/#java
Of course, all it really is is just:
if(Math.sqrt(n+1)%1.0==0.0){
... it's sunny
}
else{
... it's not sunny
}
Also, how does this make the number "sunny?"
+ 3
https://code.sololearn.com/cae54M5tf88u/?ref=app
https://code.sololearn.com/ccSa117dGNvA/?ref=app