Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 5.15 Triangle-Printing Program
- Deitel & Deitel C++ How to Program, 10th ed (Indian subcontinent adaptation)
- Visual Studio Community 2019 */
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main() {
- int x, row;
- // (a.)
- for (row = 1; row <= 10; row++) {
- for (x = 1; x <= row; x++) cout << '*';
- cout << endl;
- }
- cout << endl << endl;
- // (b.)
- for (row = 0; row < 10; row++) {
- for (x = 1; x <= 10 - row; x++) cout << '*';
- cout << endl;
- }
- cout << endl << endl;
- // (c.)
- for (row = 1; row <= 10; row++) {
- for (x = 1; x <= 10; x++) {
- //deal with spaces
- if (x < row) cout << ' ';
- else cout << '*';
- }
- cout << endl;
- }
- cout << endl << endl;
- // (d.)
- for (row = 1; row <= 10; row++) {
- for (x = 0; x < 10; x++) {
- //spaces
- if (x < 10 - row) cout << ' ';
- else cout << '*';
- }
- cout << endl;
- }
- cout << endl << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment