PROGRAM TO IMPLEMENT FIBONACCI SERIES WITH THE HELP OF TABULATION
import java.util.Scanner;
class Tabulation
{
public static void main(String[] args)
{ Scanner s=new Scanner(System.in);
int n=s.nextInt();
fib(n);
}
static void fib(int n)
{
int f[]=new int[n+1];
f[1]=1;f[0]=0;
for(int i=2;i<=n;i++)
{
f[i]=f[i-1]+f[i-2];
}
for(int i=0;i<=n;i++)
{
System.out.println(f[i]);
}
}
}
Comments
Post a Comment