+ 2
Is that code correct? Please don't answer anymore.
17 Answers
+ 4
yes its correct... try inputting
2
3
8
you'll get output as 1 (2^3 = 8)
(1.5)^(2.5) =2.75567596063(as per my calculator)
So your code is returning 0 because double has no fixed representation like integers do.
+ 4
Yes the code is correct !
+ 2
Yes the code is correct
+ 1
The code is syntactically correct but won't work as expected. double and float numbers can't be compared with == because they have no fixed representation like integers. Instead they contain small differences from rounding the result. For example 3.0 might actually be stored as 2.9999998 because the binary format can't directly store decimal numbers. Therefore using == on doubles or floats will almost always return false.
P. S. in the bool function you could return true and false instead of 1 and 0. But that's just for better readability.
+ 1
But what about you enter double variables because there are double parameters.
+ 1
Then how to make correct it?
+ 1
So one way to make it work is by rounding the decimals to a fixed places like so...
(that rounding function is taken from geeksforgeeks. com)
https://code.sololearn.com/cdTOO7Gv1Giu/?ref=app
+ 1
// 37.66666 * 100 =3766.66
// 3766.66 + .5 =3767.16 for rounding off value
// then type cast to int so value is 3767
// then divided by 100 so the value converted into 37.67
+ 1
Ok, I understand you can introduce addition function to make it simplier.
+ 1
yeah...kind of.
+ 1
for example FLOOR function.
+ 1
yeah, give it a try and share here.
+ 1
https://code.sololearn.com/cW1Myc20xzCs/?ref=app
With your help I repair it, so I use floor function on both side of == operatant. If I use floor only on left side it won't be right. I am satisfied because it makes it. One more lesson I learn.
+ 1
Yes it's correct
+ 1
Try 2 3 8....It works 😎
0
Not for all types of number.
0
Yes