ProgrammingModerate
What is the total number of elements in a triangle of rows 1 to 10, where row k has k elements?
- A. 55
- B. 45
- C. 100
- D. 66
Correct answer: A. 55
Rows 1..10 hold 1 + 2 + ... + 10 = n(n + 1)/2 = 10 x 11 / 2 = 55 elements. 45 stops at row 9, 100 treats the triangle as a full 10 x 10 square, and 66 sums up to 11.
More C Programming questions
- A program runs a loop body 10^8 times and each iteration does one multiply and one add on ints. Roughly how long does this take on typical…
- A bit-packed bitset of 10^9 bits needs how much memory?
- Which loop is correct and fast enough to find the largest element of an array of 10^7 ints, reading each value once?
- A program must answer 10^6 queries 'is x present in the set S?' where S has 10^6 values fixed in advance. Which preprocessing and query…
- How many times does a body run in for (int i = 2; i < 100; i = i)?
- Which change makes the loop for (int i = 0; i < strlen(s); i++) run in linear time?