Advertisement
simeon_petrov

HomeWork 3 triangle

Sep 5th, 2015
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. HomeWork 3 SoftUni
  2. Problem 8. Isosceles Triangle
  3.  
  4.  
  5. using System;
  6.  
  7.  
  8. namespace Triangle
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. { //Problem 8. Isosceles Triangle
  14. Console.WriteLine("Problem 8. Isosceles Triangle VARIANT 2");
  15. Console.WriteLine();
  16. Console.WriteLine("Please input the number of rows and columns of the triangle:");
  17.  
  18. int i, j;
  19. char copyRight = '\u00a9';
  20. int heigh = int.Parse(Console.ReadLine());
  21. char[][] copyRightTriangle = new char[heigh + 1][];
  22.  
  23.  
  24.  
  25. for (i = 0; i < heigh; i++)
  26. {
  27. copyRightTriangle[i] = new char[i + 1];
  28. }
  29.  
  30. //пълним матрицата
  31. for (i = 0; i < heigh; i++)
  32. {
  33. for (j = 0; j < i; j++)
  34. {
  35. if (j == 0 || j == (i - 1) || i == (heigh - 1))
  36. {
  37. copyRightTriangle[i][j] = copyRight;
  38. }
  39. }
  40. }
  41.  
  42. for (i = 0; i < heigh; i++)
  43. {
  44. Console.Write("".PadLeft((heigh - i) * 2));
  45. for (j = 0; j <= i; j++)
  46. {
  47. Console.Write("{0,3} ", copyRightTriangle[i][j]);
  48. }
  49. Console.WriteLine();
  50.  
  51. }
  52. Console.WriteLine();
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement