+ 16

Can you help me to print this pattern? 1,2,6,15,31

30th Nov 2018, 7:18 AM
Crystal!!!😎
Crystal!!!😎 - avatar
8 Antworten
+ 19
● using loop for(int i=0,a=1;i<5;i++) System.out.println(a+=i*i); ● we can do it in 1 liner recursion also (easy one , give it a try) //same loop can be used in all languages mentioned ☺👍
30th Nov 2018, 8:07 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
30th Nov 2018, 11:42 AM
Crystal!!!😎
Crystal!!!😎 - avatar
+ 13
Thanks Kishalaya Saha i hv just coded it now😊😊
30th Nov 2018, 9:31 AM
Crystal!!!😎
Crystal!!!😎 - avatar
+ 11
thanks Gaurav Agrawal 😊
30th Nov 2018, 9:31 AM
Crystal!!!😎
Crystal!!!😎 - avatar
+ 9
Here's the pattern: if we assume a[n] represents the terms of the sequence for n=0,1, 2, then a[0] = 1 and for n>0, a[n] = a[n-1] + n**2 Can you code it now? If you get stuck, show your attempt, and we'd be happy to help you out.
30th Nov 2018, 7:31 AM
Kishalaya Saha
Kishalaya Saha - avatar
+ 4
а[n] = (n(n+1)(2n+1))/6 +1
30th Nov 2018, 10:33 AM
Микола Федосєєв
Микола Федосєєв - avatar
+ 2
Well done, and you're welcome Crystal!! 😊
30th Nov 2018, 10:19 AM
Kishalaya Saha
Kishalaya Saha - avatar
21st Jul 2020, 1:13 AM
shubham kumar
shubham kumar - avatar