C Program to Count Number of Digits



In this program we will take an integer from user and count the number of digits.



  1. // C program to count number of digits
  2. #include <stdio.h>
  3. int main()
  4. {
  5. long long x;
  6. int count = 0;
  7. printf("Enter any number: ");
  8. scanf("%d", &x);
  9. while(x != 0)
  10. {
  11. count++;
  12. x/= 10;
  13. }
  14. printf("Total digits: %d", count);
  15. return 0;
  16. }

Output


Output!