# C program to Count the digits of a number

Given a number **N**, write a C program to find the count of digits in number** N**.

**Examples:**

Input:N = 12345

Output:5

Explanation:

The count of digit in 12345 = 5.

Input:N = 23451452

Output:8

Explanation:

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

## C

`// C Program to find count of ` `// digits in a number ` ` ` `#include <stdio.h> ` ` ` `// Find the count of digits ` `int` `findCount(` `int` `n) ` `{ ` ` ` `int` `count = 0; ` ` ` ` ` `// Remove last digit from number ` ` ` `// till number is 0 ` ` ` `while` `(n != 0) { ` ` ` ` ` `//Increment count ` ` ` `count++; ` ` ` `n /= 10; ` ` ` `} ` ` ` ` ` `// return the count of digit ` ` ` `return` `count; ` `} ` ` ` `// Driver program ` `int` `main() ` `{ ` ` ` `int` `n = 98562; ` ` ` `printf` `(` `"Count of digits in %d = %d\n"` `, ` ` ` `n, findCount(n)); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

**Output:**

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)Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: **DSA Self Paced**. Become industry ready at a student-friendly price.

## Recommended Posts:

- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Program to count digits in an integer (4 Different Methods)
- Find smallest possible Number from a given large Number with same count of digits
- Program to count vowels, consonant, digits and special characters in string.
- Count of prime digits of a Number which divides the number
- Count number of digits after decimal on dividing a number
- Find count of digits in a number that divide the number
- Count digits in given number N which divide N
- Count of Prime digits in a Number
- Count total number of digits from 1 to n
- Program for Sum of the digits of a given number
- C Program for Sum the digits of a given number
- Count Numbers with N digits which consists of even number of 0’s
- Count Numbers with N digits which consists of odd number of 0's
- Count of Numbers in Range where the number does not contain more than K non zero digits
- C Program to Print all digits of a given number
- Count ways to spell a number with repeated digits
- Count the number of digits of palindrome numbers in an array
- Count of numbers in Array ending with digits of number N

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.