Chudo6

Babeeva Julia-06.05.22-Трикутники

May 5th, 2022
895
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //https://shpp.gitbook.io/zero/tutorials/loops/triangles
  2. let n = +prompt('Введіть розмір сторони трикутника');
  3. //1 triangel
  4. let i = 0;
  5. while (i < n) {
  6.     let star = "";
  7.     i++;
  8.     let j = 0;
  9.     while (j < i) {
  10.         star += "*";
  11.         j++;
  12.     }
  13.     console.log(star);
  14. }
  15. console.log();
  16.  
  17. //2 triangel
  18. i = 0;
  19. while (i < n) {
  20.     let j = n, star = "";
  21.     while (j > i) {
  22.         star += "*";
  23.         j--;
  24.     }
  25.     i++;
  26.     console.log(star);
  27. }
  28. console.log();
  29.  
  30. //3 triangel
  31. i = 0;
  32. while (i < n) {
  33.     let space = "";
  34.     let j = 0;
  35.     while (j < i) {
  36.         j++;
  37.         space += " ";
  38.     }
  39.  
  40.     let star = "";
  41.     j = n;
  42.     while (j > i) {
  43.         j--;
  44.         star += "*";
  45.     }
  46.  
  47.     console.log(space + star);
  48.     i++;
  49. }
  50. console.log();
  51.  
  52. //4 triangel
  53. i = 0;
  54. while (i < n) {
  55.     i++;
  56.     let star = "", j = 0;
  57.     while (j < i) {
  58.         j++;
  59.         star += "*";
  60.     }
  61.  
  62.     let space = "";
  63.     j = n;
  64.     while (j > i) {
  65.         j--;
  66.         space += " ";
  67.     }
  68.     console.log(space + star);
  69. }
Advertisement
Add Comment
Please, Sign In to add comment