Go to Top

Tuesday, 21 February 2012

Visitor's Request - 6

Hello Harish !

You had asked for the program to print the Pascal's Triangle, which is :


1 1 
1 2 1 
1 3 3 1 
1 4 6 4 1 

Here's your program.

Java Program :

class pattern_44
{
 static void print(int b)
 {
     int[] a=new int[b];
     a[0]=1;
     int i,j,k;
     for(i=0;i<b;i++)
     {
         for(j=i-1;j>=0;j--)
         a[j+1]=a[j+1]+a[j];
         for(k=0;k<=i;k++)
         System.out.print(a[k]+" ");
         System.out.print("\n");
        }
    }
}

I would be a bit busy for this month, owing to my ICSE exams, but in case you have any more queries, be sure to communicate them to me. I would certainly try to solve it in my free time.

ShareThis