Teo_Yanchev

Methods - PringintTriangle - C# Fundamentals

Sep 10th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. namespace _4.PrintingTriangle
  5. {
  6. class Program
  7. {
  8. static void PrintTriangle(int n)
  9. {
  10. for (int row = 1; row <= n; row++)
  11. {
  12. PrintInside(row);
  13. }
  14.  
  15. for (int row = n - 1; row > 0; row--)
  16. {
  17. PrintInside(row);
  18. }
  19.  
  20. }
  21.  
  22. static void PrintInside(int row)
  23. {
  24. for (int col = 1; col <= row; col++)
  25. {
  26. Console.Write($"{col} ");
  27. }
  28. Console.WriteLine();
  29. }
  30. static void Main()
  31. {
  32. int n = int.Parse(Console.ReadLine());
  33.  
  34. PrintTriangle(n);
  35. }
  36.  
  37. }
  38. }
  39.  
Add Comment
Please, Sign In to add comment