You must Sign In to post a response.
  • Category: .NET

    Pascal triangle progaam in C# console application

    How to code the "Pascal triangle" progaam in C# console application.

    Formula:Pij = Pi-1, j-1 + Pi-1, j

    output: 1
    1 1
    1 2 1
    1 3 3 1
  • #300595
    Generating Pascal Triangle

    using System;
    class pascalTriangle
    {
    public static void Main()
    {
    int binom=1,q=0,r,x;
    Console.WriteLine("Enter the number of rows");
    string s=Console.ReadLine();
    int p =Int32.Parse(s);
    Console.WriteLine(p);
    Console.WriteLine("The Pascal Triangle");
    while(q<p)
    {
    for(r=40-(3*q);r>0;--r)
    Console.Write(" ");
    for(x=0;x<=q;++x)
    {
    if((x==0)||(q==0))
    binom=1;
    else
    binom=(binom*(q-x+1))/x;
    Console.Write(binom);
    }
    Console.Write("\n ");
    ++q;
    }
    }
    }

    --Giri
    http://giribabu.wordpress.com


This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.