+ 3

Challenge sequence 5 : 2,7,16,29,46,67,92,121,154.....code it...All languages welcome

All languages welcome...code it

12th Oct 2017, 3:31 PM
Saurabh Shah
Saurabh Shah - avatar
10 Respostas
12th Oct 2017, 5:00 PM
Ferhat Sevim
Ferhat Sevim - avatar
+ 18
@Deepak, what do you mean by "hard coded"? It's all inside the for loop...
12th Oct 2017, 4:17 PM
Maz
Maz - avatar
+ 16
(2 * n * n - n + 1) is the series generator. n = 1 => 2 - 1 + 1 = 2 n = 2 => 8 - 2 + 1 = 7 n = 3 => 18 - 3 + 1 = 16 and so on.
12th Oct 2017, 5:25 PM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 4
@krishna Teja, how were you able to get the nth term expression? (2*n^2 - n + 1) Thanks !
12th Oct 2017, 6:52 PM
Nikhith S
Nikhith S - avatar
+ 4
https://code.sololearn.com/cn6415CiyWgz/?ref=app my answer☝☝ c++❀❀
12th Oct 2017, 7:56 PM
M.s S.a
M.s S.a - avatar
13th Oct 2017, 3:55 AM
Saurabh Shah
Saurabh Shah - avatar
+ 2
2 methods...with maths formula
12th Oct 2017, 3:38 PM
Saurabh Shah
Saurabh Shah - avatar
+ 2
Logic part: for(i=1;i<n;i++) { a=(i*i)+i*(i-1)+1 printf("%d",a); a=0; } when i=1: a=1+0+1»2 when i=2: a=4+2+1»7 when i=3: a=9+6+1»17 when i=4: a=16+12+1»29 Thank you👍
13th Oct 2017, 3:03 AM
sheethal gowda
sheethal gowda - avatar
+ 1
@sk if you enter limit 9...only 2 number outputs are printed...logic is ok
13th Oct 2017, 12:19 PM
Saurabh Shah
Saurabh Shah - avatar