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.
p
is declared and initialized in the initialization statement of thefor
loop:This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
this fixes the symptoms, not the condition. your code would still fail for very large
int
s.UINT_MAX
is just twice as large asINT_MAX
, not 10 times as large. if you want to count the number of digits of a number, you should rather divide than multiplyfor (int i = 10; i <= n; i *= 10, digits++)
if
n
is very large, there is no power of10
larger thann
that can fit insidei
, so this loops forever.for example, if
n
is2,000,000,000
, the next largest power of10
is10,000,000,000
, butINT_MAX
aka2 ** 31 - 1
is2,147,483,647
Hi. The description may be unclear about that, but there is no obligation to use recursion to solve this problem. However, it's possible to use recursion to solve this problem. You should try to print stuff from your code to try to catch when your code doesn't act as it should (use
printf
).