Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int sumOfDigits(int n) {
- int result = 0;
- while (n > 0) {
- result += 1;
- n = n / 10;
- }
- return result;
- }
- int main()
- {
- int n = 0;
- int result = 0;
- cin >> n;
- for (int i = 1; i <= n; i++) {
- result += sumOfDigits(i);
- }
- cout << result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement