ProgrammingHard

A program multiplies two n x n matrices with n = 500 in int, and the product entries reach about 10^12. What is the error?

  1. A. There is no error, since matrices never overflow
  2. B. The matrix must be sorted first
  3. C. The entries overflow int, so the accumulator must be long long
  4. D. The product needs a double, which is always exact

Correct answer: C. The entries overflow int, so the accumulator must be long long

A product entry is a sum of 500 products of values near 10^6, so it can exceed INT_MAX. Using long long for the accumulator fixes it.

More C Programming questions

Exams that ask this topic