• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
August 13, 2024 |33.4K Views

Program to Count Digits in an Integer

Description
Discussion

In this video, we will see a Program to count digits in an integer.

For Example:
Input: 6785
Output: 4

Input: 78764665
Output: 8

Here we see two different methods to calculate count digits in an integer:
1. Using while loop: At first the integer entered by the user is stored in the variable n. After that the while loop is iterated until the test expression n != 0 is evaluated to 0 (false).

2. Using recursive function: 
What is recursion? 
The process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called a recursive function. Here we create a recursive function and count digit in an integer.

Program to Count Digits of an Integer: https://www.geeksforgeeks.org/program-count-digits-integer-3-different-methods/