Advertisement
kamandos

HomeWork2

Jul 14th, 2022
697
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.36 KB | None | 0 0
  1. #include <stdio.h>
  2. int main() {
  3.   long long n;
  4.   int count = 0;
  5.   printf("Enter an integer: ");
  6.   scanf("%lld", &n);
  7.  
  8.   // iterate at least once, then until n becomes 0
  9.   // remove last digit from n in each iteration
  10.   // increase count by 1 in each iteration
  11.   do {
  12.     n /= 10;
  13.     ++count;
  14.   } while (n != 0);
  15.  
  16.   printf("Number of digits: %d", count);
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement