Given a number N, write a C program to find the count of digits in number N.
Input: N = 12345
The count of digit in 12345 = 5.
Input: N = 23451452
The count of digits in 23451452 = 8.
Approach: Count of digits in a number can be found efficiently in few steps:
- Remove the last digit of number by dividing it with 10.
- Increment the count of digit by 1.
- Keep repeating steps 1 and 2 until the value of N becomes 0. In this case, there will be no more digit left in the number to count
Count of digits in 98562 = 5
Time complexity: O(D), where D is the count of digits in number N.
Auxiliary Space complexity: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.