Advertisement
RadioNurshat

NumberOfEntireDigits

Sep 27th, 2020
1,372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. using namespace std;
  4. int sumOfDigits(int n) {
  5.     int result = 0;
  6.     while (n > 0) {
  7.         result += 1;
  8.         n = n / 10;
  9.     }
  10.     return result;
  11. }
  12. int main()
  13. {
  14.     int n = 0;
  15.     int result = 0;
  16.     cin >> n;
  17.     for (int i = 1; i <= n; i++) {
  18.         result += sumOfDigits(i);
  19.     }
  20.     cout << result;
  21. }
  22.  
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement