Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
It's funny because this was actually pretty much my original answer, except that I didn't account for numbers less than zero.
The error message wasn't very helpful, so I found myself jumping through hoops trying to figure out how to handle floating point inaccuracies.
dude,It must be the best way to do this
Seemed like a simple task, but I broke my head solving it, 2 out of 3 conditions in the task were met and the last one was not accepted by me. Of course, I had to resort to help....... It turned out to be the same thing I wrote, just with some minor changes, which also turned out to be tricky, but now I see that it's even easier. I'm going to be a wreck today, work in 4 hours and I haven't slept.....
I knew there was a way to do this..
Your solution does the same you just take up another line to copy the contents of the initial string into a new one.
So that's how map works.
https://en.cppreference.com/w/cpp/numeric/math/sqrt
I have checked the following source: https://cplusplus.com/reference/cmath/sqrt/?kw=sqrt, and it did not say that
std :: sqrt
returnsNaN
when the argument is negative.Could you please point out the source of your information? I will check that source if it is more reliable/updated.
agree.
Why is this answer getting so many best practice votes? Surely since sqrt returns a floating point value, with which arithmatic is limited in precision, which could cause false answers. It would also risk undefined behaviour due to integer overflow with larger n values as squaresquare (square_rootsquare_root) reaches the max value for an int.
Calculating square roots is also much slower than other integer operations so its not really an efficient approach. Am i mistaken here or missing something?
No need to check for negatives sqrt returns -NAN for negatives square it and it gives you NAN.
using namespace is in the script automatically and hes probably used to coding properly
there is "using namespace std;" at the beginning, so why did you add "std::" to abs function?
This comment is hidden because it contains spoiler information about the solution
cool
Loading more items...