Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace PascalTriangle
- {
- class Program
- {
- static void Main(string[] args)
- {
- ShowPascal(15);
- Console.Read();
- }
- private static int PascalsCoords(int x, int y)
- {
- if (y > x)
- {
- Console.WriteLine("Error, unknown");
- return -1;
- }
- return Pascals(x - (y - 1), y);
- }
- private static int Pascals(int x, int y)
- {
- if (x == 1 || y == 1) { return 1; }
- return Pascals(x, y - 1) + Pascals(x - 1, y); ;
- }
- private static void ShowPascal(int height)
- {
- int width = 80;
- int fieldWidth = 5;
- for (int i = 1; i <= height; i++)
- {
- string leading = new String(' ', (width / 2) - (fieldWidth*i/2));
- Console.Write(leading);
- for (int j = 1; j <= i; j++)
- {
- string output = "" + PascalsCoords(i, j);
- output = output.PadRight(fieldWidth);
- Console.Write(output);
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement