Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. string msg = "";
  4. int i = 1;
  5.  
  6. while (i < 6)
  7. {
  8. int col = 0;
  9. while (col < i)
  10. {
  11. msg += i;
  12. col++;
  13. }
  14. msg += "n";
  15. i++;
  16. }
  17.  
  18. MessageBox.Show(msg);
  19. }
  20.  
  21. private void button1_Click(object sender, EventArgs e)
  22. {
  23. string msg = "";
  24. for (var i = 1; i < 6; i++)
  25. {
  26. for (var col = 0; col < i; col++)
  27. {
  28. msg += "*";
  29. }
  30. msg += "n";
  31. }
  32. for (var i = 5; i >= 1; i--)
  33. {
  34. for (var col = 0; col< i; col++)
  35. {
  36. msg += "*";
  37. }
  38. msg += "n";
  39. }
  40. MessageBox.Show(msg.Trim());
  41. }
  42.  
  43. string output = string.Empty;
  44. const string symbol = "*";
  45.  
  46. //Loop up to the half to print the upcomming way
  47. for (int i = 1; i <= 5; i++)
  48. {
  49. //Based on index i we need to print asterix
  50. for (int up = 0; up < i; up++)
  51. {
  52. output += symbol;
  53. }
  54.  
  55. //After all asterix are written to string we need a NewLine.
  56. output += Environment.NewLine;
  57. }
  58.  
  59. //Here we start the same part as above but reverse it
  60. //So counting from upper end down
  61. for (int i = 5; i >= 1; i--)
  62. {
  63. for (int down = 0; down < i; down++)
  64. {
  65. output += symbol;
  66. }
  67.  
  68. output += Environment.NewLine;
  69. }
  70.  
  71. //The Trim(); will cut any free spaces before and after the string
  72. //So we can easily cut the last NewLine which is inserted but not needed
  73. MessageBox.Show(output.Trim());
  74.  
  75. private void button1_Click(object sender, EventArgs e)
  76. {
  77. string msg = "";
  78. for (var i = 1; i < 6; i++)
  79. {
  80. for (var col = 0; col < i; col++)
  81. {
  82. msg += i;
  83. }
  84. msg += "n";
  85. }
  86. MessageBox.Show(msg);
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement