SCHOOL OF CODE BUILDERS
Learn To CODE. Become A DEVELOPER.
Pages
HOME
DATA STRUCTURES
STRINGS
ARRAYS
MATRIX
BINARY TREES
LINKED LIST
STACK
QUEUE
SORTING
SEARCHING
C
PYTHON
PSEUDOCODE
CONTEST PROBLEMS
ALGORITHMS
PATTERNS
PHP
C PUZZLES
C INTERVIEW QUESTIONS
JAVA
C++
HASHING
RECURSION
BASIC C PROGRAMS
TCS-CODEVITA
FACEBOOK
CONTACT US
C Program to Count the number of digits in an integer
C Program to Count the number of digits in an integer
Input:
12345
Output:
number of digits = 5
#include
#include
int main(void) { /* replace the below line with unsigned long long int for large integers */ int n,count=0; /* get the number from the user change the format specifier as %llu , if data type is unsigned long long int */ scanf("%d",&n); /* while n is not equal to zero */ while(n) { /* count the digits */ count++; /* remove the last digit of the number */ n/=10; } /* print the number of digits */ printf("number of digits = %d",count); return 0; }
PREVIOUS
NEXT
HOME