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!
download android app

Popular C Examples









codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube