Advertisement
Nemo048

Untitled

Jun 25th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 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 lesson10
  8. {
  9.     /*
  10.      * -Цикл выводит числа в следующем порядке:
  11. 1 +1
  12. 2 -1
  13. 1 +2
  14.  
  15. 3 +1
  16. 4 -1
  17. 3 +2
  18.  
  19. 5 +1
  20. 6 -1
  21. 5 +2
  22.  
  23. 7
  24. Или так:
  25. 1 +1
  26. 2 -1
  27. 1 +1
  28.  
  29. 2 +1
  30. 3 -1
  31. 2 +1
  32.  
  33. 3 +1
  34. 4 -1
  35. 3 +1
  36.  
  37. 4
  38. 5
  39. 4
  40. 5
  41. 6
  42.      * */
  43.     class Program
  44.     {
  45.         static void Main(string[] args)
  46.         {
  47.             int number = 1;
  48.             int directionChangeStep = 1;
  49.             int transitionStep = 1;
  50.  
  51.             for(int i = 0; i < 20; i++)
  52.             {
  53.                 Console.WriteLine(number);
  54.                 number += directionChangeStep * (int)Math.Pow(-1, i % 3) + transitionStep * ((int)Math.Pow(-1, i % 3) + (int)Math.Pow(-1, (i + 1) % 3)) / 2;
  55.             }
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement