215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 21000?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | #include <iostream> #include <Windows.h> using namespace std; #define MAX_POW 1000 void main() { int digitArr[1024] = { 0 }; digitArr[0] = 2; int overFlow = 0; for (int pow = 1; pow <= MAX_POW - 1; ++pow) for (int arr_idx = 0; arr_idx < 1024; ++arr_idx) { if (overFlow == 1) { digitArr[arr_idx] *= 2; digitArr[arr_idx] += 1; overFlow = 0; } else { digitArr[arr_idx] *= 2; } if (digitArr[arr_idx] >= 10) { overFlow = 1; digitArr[arr_idx] %= 10; } } int sum = 0; for (int arr_idx = 0; arr_idx < 1024; ++arr_idx) sum += digitArr[arr_idx]; cout << sum << endl; system("pause"); } |
댓글 없음:
댓글 쓰기