write a method to calculate and return the sum of square of the digits of number 'n'. the method declaration is as follows: int Tribonacci (int n)
Answers
Language used : Python Programming
Tribonacci is just like fibanocci, with a slight difference. In fibanocci, from the third term of the series you keep on adding the immediate previous two terms to get the next one.
While, In tribonacci, from the fourth term of the series you keep on adding the immediate previous three terms to get the next one.
Note :
I have attached the interpretation of the program, below as an attachment. Have a look to see how it get computed. Bolded code in the program refers the method used to get tribonacci.
Program :
import java.util.Arrays;
import java.util.Scanner;
public class Something
{
static int[] Tribonocci(int n)
{
int a[]=new int[n];
a[0] = a[1] = 0;
a[2] = 1;
for (int i = 3; i < n; i++)
a[i] = a[i - 1] + a[i - 2] + a[i - 3];
return a;
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(); //length of the series
int[] a = Tribonocci(n);
for (int i = 0; i < n; i++)
System.out.print(a[i] + " ");
}
}
Input :
20
Output :
0 0 1 1 2 4 7 13 24 44 81 149 274 504 927
Hope it helps. If yes, leave a smile. :)
Answer:
Explanation
Here your answer hope it helps