int digits=ceil(log10(n));
What does this line mean? Will it count the number of digits in n? If yes then how?
Int digits=ceil(log10(n));
@tanyaa.sood, log10(n): this function returns the log base 10 value of n the return type is double , The ceil() function in C++ returns the smallest possible integer value which is greater than or equal to the given argument.
so ciel(log10(n)) returns the smallest possible integer value which is greater than or equal to the log base 10 value of n
yes it does count the digits in n ,
For an integer number
that has n
digits, it’s value is between 10^(n - 1)
(included) and 10^n
, and so log10(number)
is between n - 1
(included) and n
. Then the function ceil
cuts down the fractional part, leaves the result as n
.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.