Learn
Exam

Calculate the Sum of Even Numbers within a Range

Difficulty
STARTER

Problem

Given two natural numbers start and end, write a function solution that returns the sum of even numbers between start and end (inclusive).


Constraints

  • start and end are natural numbers between 1 and 100 inclusive.
  • start is less than or equal to end.
  • There will always be at least one even number between start and end.

Test Case

Test Case Number start end return
1 1 10 30
2 4 8 18
3 6 6 6

Explanation for Test Case 1

  • When start = 1 and end = 10, the even numbers between 1 and 10 are 2, 4, 6, 8, 10, and their sum is 2 + 4 + 6 + 8 + 10 = 30.

Explanation for Test Case 2

  • When start = 4 and end = 8, the even numbers between 4 and 8 are 4, 6, 8, and their sum is 4 + 6 + 8 = 18.

Explanation for Test Case 3

  • When start = 6 and end = 6, the only even number between them is 6, so the sum is 6.