Program to display Pascal’s Triangle in Java

 Program to display Pascal’s Triangle

class P14
{
    public static void main(String args[])
    {
        int m=0,x,b;
        do
        {
            x=0;b=1;
            while(x<=m)
            {
                if(m==0||x==0)
                    System.out.print("   "+b);
                else
                {
                     b=b*(m-x+1)/x;
                     System.out.print("   "+b);
                }
                x=x+1;
            }
            System.out.println("\n");
            m=m+1;
        }
        while(m<=5);
    }
}

       

7 comments:

Snehashis Ghosh said...

Format of triangle is not coming.

Snehashis Ghosh said...

Format of triangle is not coming.

Anonymous said...

Hello my friend! I want to say that this post is awesome,
nice written and include almost all significant infos.
I would like to look more posts like this .

Also visit my weblog - how to file for bankruptcy in florida

Anonymous said...

Hey There. I discovered your weblog the use of msn. That is an extremely well
written article. I will make sure to bookmark it and come
back to read extra of your helpful information.
Thank you for the post. I will definitely return.


My site: bankruptcy laws in florida

Anonymous said...

the program is correct, but the output has to be in the shape of a pyramid. please help me with it.

Zeeniya said...
This comment has been removed by the author.
Anonymous said...

how can we bring the output to be in the shape of a pyramid??plzzzzz help!!!

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|