avr39ripe

cppTrianglesTask

Feb 8th, 2022 (edited)
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5.     const int maxSize{ 9 };
  6.     const char pos{ '*' };
  7.     const char neg{ ' ' };
  8.     bool positive{ false };
  9.  
  10.     for (int y{ 0 }; y < maxSize; ++y)
  11.     {
  12.         for (int x{ 0 }; x < maxSize; ++x)
  13.         {
  14.             //positive = ((x + y == maxSize - 1) or (x == y));
  15.             positive = ((x + y <= maxSize -1)) and (x >= y);
  16.             std::cout << ' ' <<  (positive ? pos : neg) << ' ';
  17.         }
  18.         std::cout << '\n';
  19.     }
  20.     std::cout << '\n';
  21.  
  22. }
  23.  
  24.     //  a > b -> mA < mB
  25.     // -2 -1 0 1 2
  26.     // a = 2 b = 1
  27.     // a > b = true
  28.     // a = -2 b = -1
  29.     // mA < mB = true
  30.  
  31. //a maxSize = 4
  32. //      0   1   2   3  
  33. //  0   *   *   *   *
  34. //  1       *   *   *
  35. //  2           *   *
  36. //  3               *
  37.  
  38. //B maxSize = 4
  39. //      0   1   2   3  
  40. //  0   #   #   #   *
  41. //  1   #   #   *   #
  42. //  2   #   *   #   #
  43. //  3   *   #   #   #
  44.  
Add Comment
Please, Sign In to add comment