Advertisement
avr39ripe

cppRectTriangleDraw

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