0

Why is output 1-2-4-7-11 instead of 1-2-4-8-16?

https://code.sololearn.com/WBQLFX474HZC/?ref=app

24th Jan 2021, 3:12 PM
Тимур Завьялов
Тимур Завьялов - avatar
5 Réponses
+ 2
Тимур Завьялов arr[i] = arr[i-1]+i; For i=3 arr[3] = arr[2] + 3 => 4 + 3 { as arr[2] is 4 as calculated above } Similar is the case of arr[4] I am curious to know how are you calculating it to be 8 and 16 ?
24th Jan 2021, 4:52 PM
Arsenic
Arsenic - avatar
+ 7
arr[0] = 1 { initialization } arr[1] = arr[0] + 1 => 1+1 = 2 arr[2] = arr[1] + 2 => 2+2 = 4 arr[3] = arr[2] + 3 => 4+3 = 7 arr[4] = arr[3] + 4 => 7+4 = 11
24th Jan 2021, 3:20 PM
Arsenic
Arsenic - avatar
+ 1
Arsenic, thank you, I got it)
24th Jan 2021, 4:58 PM
Тимур Завьялов
Тимур Завьялов - avatar
0
Do dry run and put values one by on write values on copy u will understood self
24th Jan 2021, 3:21 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
Arsenic, can you explain me why 4+3 and 7+4?
24th Jan 2021, 4:23 PM
Тимур Завьялов
Тимур Завьялов - avatar