avr39ripe

BR012nestedLoopsPractice

Feb 9th, 2021
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <chrono>
  3. #include <thread>
  4.  
  5. /*
  6. * side = 5
  7. *
  8. *
  9.     0   1   2   3   4
  10. 0   #   #   #   #   #
  11. 1   #   #   #   #   #
  12. 2   #   #   #   #   #
  13. 3   #   #   #   #   #
  14. 4   #   #   #   #   #
  15.  
  16.  
  17.     0   1   2   3   4
  18. 0   *   *   *   *   *
  19. 1   #   *   *   *   *
  20. 2   #   #   *   *   *
  21. 3   #   #   #   *   *
  22. 4   #   #   #   #   *
  23.  
  24.  */
  25.  
  26. // -4   -3  -2  -1  0   1   2   3   4
  27. //       b   >   a      a   <   b
  28.  
  29. // a < b
  30.  
  31. // a > b
  32.  
  33. // a >= b
  34. // -a <= -b
  35.  
  36. int main()
  37. {
  38.  
  39.     int side{5};
  40.     //std::cout << "enter line length\n";
  41.     //std::cin >> side;
  42.     char symb = '#';
  43.  
  44.     for (int y{ 0 }; y < side; ++y)
  45.     {
  46.         for (int x{ 0 }; x < side; ++x)
  47.         {
  48.             symb = '*';
  49.  
  50.             //if ((x + y == (side - 1)) or (x == y))
  51.             if (x + y >= (side - 1) or (x <= y))
  52.             {
  53.                 symb = ' ';
  54.             }
  55.  
  56.             std::cout << ' ' << symb << ' ';
  57.            
  58.         }
  59.         std::cout << '\n';
  60.     }
  61.  
  62.     return 0;
  63. }
  64. //std::this_thread::sleep_for(std::chrono::milliseconds(200)); //make some pause for better output look :)
Advertisement
Add Comment
Please, Sign In to add comment