C Program to find the number of digits in an integer

Finding the number of digits in an integer in C

Today, we will be learning how to find the number of digits in an integer in C . An integer is made up of a group of digits, i.e; it is a combination of digits from 0-9

Here we will use loops along with an arithmetic operator.This program takes an integer from the user and calculates the number of digits. For example: If the user enters 6589, the output of the program will be 4.

number of digits in an integer in C

Algorithm:-

Step 1: Start 

Step 2: The user is asked to insert an integer or number 

Step 3: The variable entered by user is stored in variable ‘a’ 

Step 4: The while loop is iterated till the last expression. 

Step 5: After the count, printf “Number of digits” 

Step 6: Stop 

C Program to find the number of digits in an integer
Competitive Coding Techniques

C Code:-

#include <stdio.h>

int main()
{
//to initialize of variable
int count=0;
int n,c;

//to take user input
printf("enter the number: ");
scanf("%d",&n);
c=n;

//when number is zero
if(n==0)
printf("digit is 1");
//false condition

else
{
while(n!=0)
{
//find last digit of number
n=n/10;
//count of a number
++count;
}
printf("the total digit in giving number %d is : %d",c,count);
}
return 0;
}
Output:
enter the number: 3452 
the total digit in giving number 3452 is : 4