ProgrammingHardTCS NQT · Infosys
What is the sum of the decimal digits of 2^20 = 1048576?
- A. 31
- B. 28
- C. 26
- D. 35
Correct answer: A. 31
The digits are 1, 0, 4, 8, 5, 7, 6, which sum to 31. Digit sums in competitive code are usually computed with a loop of n % 10 and n / 10.
More C Programming questions
- uint16t a = 40000, b = 40000; uint32t s = a + b; What is s?
- uint32t x = 0x80000001u; x = (x << 1) | (x >> 31); What is x?
- unsigned char c = 0x7F; c = c 2 + 2; What is c?
- For the array {4, 1, 3}, how many index pairs i < j have a[i] > a[j]? These pairs are called inversions.
- How many binary strings of length 5 contain no two adjacent 1s?
- char s[] = "abc"; s[0] = 'x'; printf("%s", s); prints what?