Pascal’s triangle (recursion)

class pascaltriangle
{
public static void main (String[] args)
{
for ( int i =0;i<9; i++)
{
for ( int j =0;j<=i; j++)
System.out.print(c(i,j)+”\t”);
System.out.println();
}
}
static long c(int n,int k)
{
if ( k<=0 || k>=n) return 1;
return c(n-1,k) + c(n-1,k-1);
}
}

 

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.