ProgrammingVery hardGATE CS · Campus placements
uint32_t n = 100000u; uint32_t t = n * (n + 1) / 2; What is t?
- A. 5000050000
- B. 705082704
- C. 1410165408
- D. 705082703
Correct answer: B. 705082704
n * (n + 1) = 10000100000 wraps modulo 2^32 to 1410165408 before the division, and halving gives 705082704. Computing in uint64_t, or dividing first on the even factor, gives the correct 5000050000.
More C Programming questions
- int x = 0; for (int i = 0; i < 5; i++) x = x ^ i << 1; What is x at the end?
- uint16t a = 300, b = 300; uint16t p = a b; What is p?
- What does printf("%d", strcmp("apple", "Apple") > 0) print?
- A stair can be climbed by 1, 2 or 3 steps. How many ways are there to climb 4 stairs?
- #define N 3 and int a[N 2 + 1]; What is sizeof a / sizeof a[0]?
- int x = 5, y = 3; What does printf("%d", x & y | 4 ^ 1) print?