Viktor_Profa

Viktor Viktorovich - 10.06.2022 - Числовий ряд

Jun 8th, 2022 (edited)
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //https://shpp.gitbook.io/zero/tutorials/loops/numbers_sequence
  2. let x = +prompt("введіть натуральне число");
  3. //Перша частина
  4.  
  5. let y = 1
  6. while (y <= x) {
  7.     console.put(y)
  8.     if (y < x) {
  9.         console.put(",")
  10.     }
  11.     y++
  12. }
  13. console.log("\n")
  14.  
  15. //Друга частина
  16.  
  17. for (y = 1; x >=y; y++ ) {
  18.     console.put(y)
  19.     if (y < x){
  20.         console.put(",")
  21.     }
  22. }
  23. console.log("\n")
  24.  
  25. //Третя частина
  26. y = x
  27.  while (y >= 1){
  28.      console.put(y)
  29.      if (y > 1)
  30.      console.put(",")
  31.      y--
  32.  }
  33. console.log("\n")
  34. //Четверта частина
  35. y = 1
  36. for(y = x; y>= 1; y--){
  37.     console.put(y)
  38.     if (y > 1){
  39.         console.put(",")
  40.     }
  41. }
  42. console.log("\n")
  43.  
  44. //П'ята частина
  45.  
  46. y = 1
  47. while (x > y){
  48.     y++
  49.     if (y % 2 == 0){
  50.         console.put(y)
  51.     }else if (y<x){
  52.         console.put(",")
  53.     }
  54. }
  55. console.log("\n")
  56.  
  57. //Шоста частина
  58.  
  59. for(y=2; x >= y; y ++){
  60.     if (y % 2 == 0){
  61.         console.put(y)
  62.     }else if (x>y){
  63.         console.put(",")
  64.     }
  65. }
  66. console.log("\n")
  67.  
  68. //Сьома частина
  69. y = x
  70.  
  71. while (y > 1){
  72.     if (y % 2 == 0){
  73.         console.put(y)
  74.        
  75.     }
  76.  
  77.  else if (y < x){
  78.      console.put(",")
  79.     } y--
  80. }
  81. console.log("\n")
  82.  
  83. //Восьма частина
  84.  
  85. for(y=x; y>1; y--){
  86.     if (y % 2 == 0){
  87.         console.put(y)
  88.     }
  89. else if (y < x){
  90.     console.put(",")
  91. }
  92. }
  93.  
Add Comment
Please, Sign In to add comment