#include<stdio.h>
#include<iostream>
using namespace std;
int fabi(int);
int main()
{
int num,i,num1=0,num2=0,num3=1,nex;
cout<<"enter the number: ";
cin>>num;
for(i=0;i<=num;i++)
{
if ( i <= 1 )
nex = i;
else
{
nex = num1 + num2 + num3;
num1= num2;
num2 = num3;
num3 = nex;
}
cout << nex;
cout<<",";
}
cout<<endl;
system("pause");
return 0;
}
Instead of putting the if statement you can directly print 0 1 2 in the beginning of the Tribonacci Series as the first three element do not change and in for loop just make the condition as (i<n-3)
ReplyDelete