Advertisement
Viktor_Profa

Числовий ряд

Jun 21st, 2022
51
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.  
  3. let N = +prompt("Введіть число")
  4. //від 1 до N включно, через while
  5. let a = 1
  6. while(N >= a){
  7.     console.put(a)
  8.     if (N > a){
  9.          console.put(",")}
  10.     a++
  11. }
  12. console.log("\n")
  13. //від 1 до N включно, через for
  14.  
  15. for(a = 1; N >= a; a++){
  16.     console.put(a)
  17.     if (a == N) continue
  18.     console.put(",")
  19.  
  20. }
  21.  
  22. console.log("\n")
  23.  
  24. //від N до 1 включно, через while
  25. let G = N
  26. a = 1
  27.  
  28. while(G >= a){
  29.     console.put(G)
  30.     if (G > a){
  31.         console.put(",")
  32.     }
  33.     G--
  34. }
  35. console.log("\n")
  36.  
  37. //від N до 1 включно, через for
  38. let H = N
  39. a = 1
  40. for(a = 1; H >= a; H--){
  41.     console.put(H)
  42.     if (H == a)continue
  43.     console.put(",")
  44. }
  45.  
  46. console.log("\n")
  47.  
  48. //парні від 2 до N включно, через while
  49.  
  50. a = 2
  51.  
  52.  
  53. while(a <= N){
  54.    console.put(a)
  55.   if (a < N){
  56.    console.put(",")}
  57.    a = a + 2
  58. }
  59.  
  60. console.log("\n")
  61.  
  62. //парні від 2 до N включно, через  for
  63. a = 2
  64.  
  65. for(a = 2; a <= N; a = a + 2){
  66.     console.put(a)
  67.     if(a < N){
  68.         console.put(",")
  69.     }
  70. }
  71.  console.log("\n")
  72.  
  73.  //парні від N до 2 включно, через while
  74.  
  75. a = 2
  76. let Z = N
  77.  
  78. while(a <= Z){
  79.     console.put(Z)
  80.     if (a < Z){
  81.         console.put(",")}
  82.     Z = Z - 2
  83.        
  84. }
  85.  
  86. console.log("\n")
  87. //парні від N до 2 включно, через for
  88.  
  89.  
  90.  
  91. for(a = 2; a <= N; N = N - 2){
  92.     console.put(N)
  93.     if(N > a){
  94.         console.put(",")
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement