Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Bonsai Boy of New York Bonsai Trees and Accessories

BlueHost Web Hosting

Liquid Web iThemes WordPress Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Liquid Web Cloud VPS Hosting

10,936 questions

14,844 answers

573 users

How to calculate and print the Pascal triangle in C#

1 Answer

0 votes
using System;
 
class Program
{
    static void Main()
    {
        int n = 5;
        
        for (int i = 0; i < n; i++) {
            int number = 1;
  
            for (int j = 0; j < (n - i) * 2; j++)
               Console.Write(" ");
  
            for (int j = 0; j <= i; j++) {
               Console.Write("{0, 4}", number);
               number = number * (i - j) / (j + 1);
            }
            Console.WriteLine();
        }
    }
}
 
 
/*
run:
 
             1
           1   1
         1   2   1
       1   3   3   1
     1   4   6   4   1
 
*/

 




answered May 11 by avibootz
edited May 11 by avibootz
...