Sum of odd numbers

Lee·2022년 8월 26일
0

Algorithm

목록 보기
81/92
post-thumbnail

❓ Sum of odd numbers

Q. Given the triangle of consecutive odd numbers:

         1
      3     5
   7     9    11

13 15 17 19
21 23 25 27 29
...
Calculate the sum of the numbers in the nth row of this triangle (starting at index 1) e.g.: (Input --> Output)

1 --> 1
2 --> 3 + 5 = 8

✔ Solution

//#my solution
function rowSumOddNumbers(n) {
	// TODO
   return n * n * n;
}

//#other solution
function rowSumOddNumbers(n) {
  return Math.pow(n, 3);
}
profile
Lee

0개의 댓글