ProgrammingVery hardGATE CS · Campus placements

uint32_t n = 100000u; uint32_t t = n * (n + 1) / 2; What is t?

  1. A. 5000050000
  2. B. 705082704
  3. C. 1410165408
  4. 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

Exams that ask this topic