Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Wzorki
  8. {
  9. class Program
  10. {
  11. const char CHAR = '*';
  12. static void Star() => Console.Write(CHAR);
  13. static void StarLn() => Console.WriteLine(CHAR);
  14. static void Space() => Console.Write(" ");
  15. static void SpaceLn() => Console.WriteLine(" ");
  16. static void NewLine() => Console.WriteLine();
  17.  
  18. public static void Trojkat(int n)
  19. {
  20. if (n % 2 == 0) n = n - 1;
  21. //górna podstawa
  22. for (int i = 0; i < n; i++)
  23. {
  24. Star();
  25. }
  26. NewLine();
  27.  
  28. //środek
  29. for (int i = 1; i < (n / 2); i++)
  30. {
  31. for (int j = 0; j < i; j++)
  32. {
  33. Space();
  34. }
  35. Star();
  36. for (int j = n - 2 - (2 * i); j > 0; j--)
  37. {
  38. Space();
  39. }
  40. StarLn();
  41. }
  42.  
  43. //czubek
  44. if (n % 2 == 1)
  45. {
  46. for (int i = 0; i < n / 2; i++)
  47. {
  48. Space();
  49. }
  50. StarLn();
  51. }
  52. }
  53. public static void Main(string[] args)
  54. {
  55. Console.WriteLine("Podaj rozmiar figury: ");
  56. int n = Convert.ToInt32(Console.ReadLine());
  57. Trojkat(n);
  58. Console.ReadKey();
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement