jeudi 22 septembre 2022

Reverse right angle triangle pattern with numbers and asterisks using for-loops in C++

first time posting here, I'd like help with getting the output of the code upside down while still using the for commands, below is the best I can put in a clarification.

Desired Output:                 Actual Output:

123456                            1*****
12345*                            12****
1234**                            123***
123***                            1234**
12****                            12345*
1*****                            123456

Code:

#include <iostream>

using namespace std;

int main() {
    int num, row, integ;

    cout << "Please enter size: ";
    cin >> integ;

    for (row = 1; row <= integ; row++) {
        for (num = 1; num <= row; num++) {
            cout << num;
        }
        for (; num <= integ; num++) {
            cout << "*";
        }
        cout << endl;
    }
}

Aucun commentaire:

Enregistrer un commentaire