Challenge sequence 5 : 2,7,16,29,46,67,92,121,154.....code it...All languages welcome | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
+ 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
12th Oct 2017, 5:00 PM
Ferhat Sevim
+ 18
@Deepak, what do you mean by "hard coded"? It's all inside the for loop...
12th Oct 2017, 4:17 PM
Maz
12th Oct 2017, 4:12 PM
Maz
+ 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
+ 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
12th Oct 2017, 7:56 PM
M.s S.a
+ 3
13th Oct 2017, 3:55 AM
Saurabh Shah
+ 2
2 methods...with maths formula
12th Oct 2017, 3:38 PM
Saurabh Shah
+ 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
+ 1
@sk if you enter limit 9...only 2 number outputs are printed...logic is ok
13th Oct 2017, 12:19 PM
Saurabh Shah