Program to Count the Number of digits in C
Now, we'll observe a way to count the amount of digits in an integer. This integer is nothing but the quantity entered by the user.
Approach
- Firstly, the quantity are going to be entered by the user. Suppose we declare the variable 'num' and stores the integer value within the 'num' variable.
- Now we are going to create ages loop and given a condition that condition is 'num' isn't up to zero.
- Suppose the worth of 'num' is 123.
- When the primary iteration executes, the worth of 'num' are going to be 123, and also the value of count are going to be incremented to 1.
- When the second iteration executes, the worth of 'num' are 12, and also the value of count are incremented to 2.
- When the third iteration executes, the worth of 'num' are 1, and therefore the value of count are incremented to three.
- After the completion of the third iteration, the worth of 'num' becomes 0, and loop is terminated because it doesn't satisfy the condition (n!=0)