The sum of all numbers
Dearest esteemed reader. It is a truth universally acknowledged that all developers at some stage in their lives must go through a technical interview. There are various levels of interrogations: some just on the level of “Please tell me something about yourself” (these are the hardest), while some go deeper and might even ask you to write some code on a blackboard or even a computer.
One of the programs that very frequently comes up in interview questions is to write some code that will calculate the sum of a series of numbers sharing a certain peculiarity, for example, the sum of all even numbers, the sum of all numbers divisible by, let’s say, five, or the sum of odd numbers in a specific interval.
For simplicity’s sake, let’s stick to something simple: the sum of all odd numbers up to 100. The following quick program delivers exactly this:
#include <cstdio> int main() { int sum = 0...