Advertisement
sifat3d

Count how many integers are in a number in C

Jun 16th, 2015
559
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.27 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int countnums(int x);
  4.  
  5.  
  6. int main()
  7. {
  8.     int input;
  9.     scanf("%d",&input);
  10.     printf("%d",countnums(input));
  11. }
  12.  
  13.  
  14. int countnums(int x)
  15. {
  16.     int count;
  17.     for(count=0;x!=0;count++)
  18.     {
  19.         x=x/10;
  20.     }
  21.     return count;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement