sum of first n odd numbers code example
Example 1: first n even numbers sum javascript
// return the sum of the first n even numbers recursively. Assume n > 0
function firstEvenNumbersSum(n) {
if (n === 0) {
return 0;
}
let num = (n * 2);
let sum = num + firstEvenNumbersSum(n-1)
return sum;
}
Example 2: check odd numbers numpy
# Input
arr = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
arr[arr % 2 == 1]
#> array([1, 3, 5, 7, 9])