Today I would like to share with you guys a program that is written by a close friend of mind, a fellow software engineer and expert C# developer Mr. Alfel Benvic G. Go he wrote this program we called Pascal Triangle using C#. First of all thank you Sir Bon for sharing this program to us. What does the program will do is to ask the user to give a number and then our program will generate the corresponding pascal triangle pattern in C#. I hope you will find the work of Sir Bon useful. Thank you.
Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.
My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
Sample Program Output
Program Listing
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PascalTriangle
{
class Program
{
static void Main(string[] args)
{
Int32 bin;
Int32 p;
Int32 q;
Int32 r;
Int32 x;
Console.Write("Enter No of Rows: ");
r = Convert.ToInt32(Console.ReadLine());
bin = 1;
q = 0;
while (q < r)
{
for (p = 40 - 3 * q; p > 0; p--)
Console.Write(" ");
for (x = 0; x <= q; x++)
{
if ((x == 0) || (q == 0))
bin = 1;
else
bin = (bin * (q - x + 1)) / x;
Console.Write(" ");
Console.Write(bin);
}
Console.WriteLine("");
q++;
}
Console.ReadLine();
}
}
}