garryhtreez

6.22

Dec 9th, 2020
786
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. /* 6.22 Triangle of Asterisks
  2.       Deitel & Deitel C++ How to Program, 10th ed (Indian subcontinent adaptation)
  3.       Visual Studio Community 2019
  4. */
  5. #include < iostream>
  6. using namespace std;
  7.  
  8. void triangle(int height) {
  9.    for (int row = 1; row <= height; row++) {
  10.       for (int col = 1; col <= row; col++) {
  11.          cout << "*";
  12.       }
  13.       cout << endl;
  14.    }
  15. }
  16.  
  17. int main()
  18. {
  19.    int height{ 0 };
  20.  
  21.    while (true) {
  22.       cout << "Enter height of triangle ( 0 to exit ): ";
  23.       cin >> height;
  24.       if (height == 0) break;
  25.       else triangle(height);
  26.    }
  27.    return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment