garryhtreez

5.15

Nov 14th, 2020 (edited)
890
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. /* 5.15 Triangle-Printing Program
  2.    Deitel & Deitel C++ How to Program, 10th ed (Indian subcontinent adaptation)
  3.    Visual Studio Community 2019 */
  4.  
  5. #include <iostream>
  6. #include <iomanip>
  7. using namespace std;
  8.  
  9. int main() {
  10.    int x, row;
  11.  
  12.    // (a.)
  13.    for (row = 1; row <= 10; row++) {
  14.       for (x = 1; x <= row; x++) cout << '*';
  15.       cout << endl;
  16.    }
  17.    cout << endl << endl;
  18.  
  19.    // (b.)
  20.    for (row = 0; row < 10; row++) {
  21.       for (x = 1; x <= 10 - row; x++) cout << '*';
  22.       cout << endl;
  23.    }
  24.    cout << endl << endl;
  25.  
  26.    // (c.)
  27.    for (row = 1; row <= 10; row++) {
  28.       for (x = 1; x <= 10; x++) {
  29.          //deal with spaces
  30.          if (x < row) cout << ' ';
  31.          else cout << '*';
  32.       }
  33.       cout << endl;
  34.    }
  35.    cout << endl << endl;
  36.  
  37.    // (d.)
  38.    for (row = 1; row <= 10; row++) {
  39.       for (x = 0; x < 10; x++) {
  40.          //spaces
  41.          if (x < 10 - row) cout << ' ';
  42.          else cout << '*';
  43.       }
  44.       cout << endl;
  45.    }
  46.    cout << endl << endl;
  47.  
  48.    return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment