fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace PascalsTriangle
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. int n;
  13. Console.Write("Enter the number of rows: ");
  14. n = Convert.ToInt32(Console.ReadLine());
  15. for (int y = 0; y < n; y++)
  16. {
  17. int c = 1;
  18. Console.WriteLine("\t");
  19. int centeringNum = (n - y);
  20. if (y % 2 != 0)
  21. {
  22. centeringNum++;
  23. }
  24. else
  25. {
  26. Console.Write(" ");
  27. }
  28. for (int j = 0; j < (centeringNum); j++)
  29. {
  30. Console.Write(" ");
  31. }
  32. for (int x = 0; x <= y; x++)
  33. {
  34. Console.Write(c + " ");
  35. c = c * (y - x) / (x + 1);
  36. }
  37. Console.Write(" ");
  38. }
  39. Console.ReadLine();
  40. }
  41. }
  42. }
Success #stdin #stdout 0.03s 36944KB
stdin
Standard input is empty
stdout
Enter the number of rows: