find S78 for sequence of odd natural numbers from 1 to 33
Answers
Answered by
0
1 + 3 + 5 + ... + (2n-1) = ?
The sum of the first n numbers of an arithmetic sequence can be derived from this formula
The values of a, d and n are:
a = 1 (the first term)
d = 2(the “common difference” between terms)
n = 3(how many terms to add up)
Therefore, the sum of the first 3 odd numbers becomes
S = (n/2) * (2a + (n - 1)d)
= (3/2) * (2 * 1 + (3 - 1)2)
= (3/2) * (2 + 2 * 2)
= (3/2) * (2 + 4)
= (3/2) * 6
= 3 * 3
= 9
Let’s prove if it works
X₁ = 1
X₂ = 1 + 3 = 4 = 2²
X₃ = 1 + 3 + 5 = 9 = 3²
From this, the answer seems to be
1 + 3 + 5 + ... + (2n-1) = n²
Let’s put that into code
>>>>>>>>>>>>>> Ruby <<<<<<<<<<<<<<<<
def sum_odd_numbers(n)
puts n ** 2
end
Similar questions