Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 5.21 Modified Triangle-Printing Program
- Deitel & Deitel C++ How to Program, 10th ed. (Indian subcontinent adaptation)
- Visual Studio Community 2019
- */
- #include <iostream>
- using namespace std;
- int main() {
- int y, row;
- int const MAX = 10;
- for ( row = 1; row <= MAX; row++ ) {
- // print asterisks for 1st triangle
- for ( y = 1; y <= row; y++ )
- cout << "*";
- // print spaces for 1st triangle
- for ( y = row + 1; y <= MAX; y++ )
- cout << " ";
- cout << " ";
- // print asterisks for 2nd triangle
- for ( y = 0; y <= ( MAX - row ); y++ )
- cout << "*";
- // print spaces for 2nd triangle
- for ( y = 1; y < row; y++ )
- cout << " ";
- cout << " ";
- // print spaces for 3rd triangle
- for ( y = 1; y < row; y++ )
- cout << " ";
- // print asterisks for 3rd triangle
- for ( y = 0; y <= ( MAX - row ); y++ )
- cout << "*";
- cout << " ";
- // print spaces for 4th triangle
- for (y = row + 1; y <= MAX; y++)
- cout << " ";
- // print asterisks for 4th triangle
- for ( y = 1; y <= row; y++ )
- cout << "*";
- cout << "\n"; // carriage return then back to loop
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment