Embercode
✕
C++ LoopsCoding problems

C++ Loops: coding problems

Write a program that reads the input and prints the answer. Run checks it against every test, including hidden ones.

0 of 8 solved

  • A bakery sells boxes numbered from a to b. Box numbers are whole numbers, and the owner wants the total of all the **odd** box numbers in that range, counting both ends.

    Negative numbers count too. For example, -3 is odd.

    Use a for loop that tries every number from a to b, and add the odd ones.

    Input. One line with two integers `a` and `b`, where `a <= b` and both are between -1000000 and 1000000.

    Output. One integer: the sum of all odd numbers from `a` to `b`.

    Example 1 input

    1 10
    

    Output

    25
    

    Example 2 input

    -5 5
    

    Output

    0