C Program to Find Number of Digits in an Integer Value
ADVERTISEMENTS
C program to find the number of digits in an integer value.
In this article, you will learn how to count the number of digits in the input integer value.
Example
Enter an integer value: 3456
Total 4 digits in '3456'
Source
// C Program to Find Number of Digits in an Integer Value
#include <stdio.h>
// It's the main function of the program
int main() {
long long number = 0;
long long temp_num;
int count = 0;
// Step-1 Take input from the User
printf("Enter an integer value: ");
scanf("%lld", &number);
temp_num = number;
// Step-2 Iterate over the `number` variable using the while loop
while (number != 0) {
number /= 10;
count++; // Increment count of the Number
}
// Step-3 Final output of the program
printf("\nTotal %d digits in '%lld'\n", count, temp_num);
return 0;
}
Output
Enter an integer value: 55326
Total 5 digits in '55326'