I'm not sure if this is right

I need some big time help with this Code please help?
Write a recursive C++ Function unsigned long trib(int n) which returns the nth (1=<n=<38) tribonacci according to the recursive formula
T1 =T2 =T3=1
Tn=Tn-1+Tn-2+Tn-3


if (n<=3)
{
return 1;
}
else
{
return trib(n-1)+trib(n-2)+trib(n-3)
}
tribonacci is it the name of some mathematicion?:)

1
2
3
4
unsigned long trib( unsigned int n )
{
   return ( ( n < 3 ) ? 1 : trib( n - 1 ) + trib( n - 2 ) + trib( n - 3 ) );
}


I am assuming that the numbers start from T0 that is T0 = 1, T1 = 1, and T2 = 1.


Last edited on
Topic archived. No new replies allowed.