Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Disclosure: My content contains affiliate links.

43,700 questions

57,013 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, 2019 by avibootz
edited May 11, 2019 by avibootz

Related questions

1 answer 201 views
2 answers 256 views
1 answer 212 views
1 answer 214 views
1 answer 1,053 views
1 answer 265 views
3 answers 462 views
...