write a program to print tribonacci series in c language
// A simple recursive CPP program to print
// first n Tribonacci numbers.
#include<stdio.h>
#include<conio.h>
int printTribRec(int n)
{
if (n == 0 || n == 1 || n == 2)
return 0;
if (n == 3)
return 1;
else
return printTribRec(n - 1) +
printTribRec(n - 2) +
printTribRec(n - 3);
}
void printTrib(int n)
{
for (int i = 1; i < n; i++)
printf("\n%d ",printTribRec(i));
}
// Driver code
int main()
{
int n = 30;
printTrib(n);
return 0;
}
Comments
Post a Comment