Answer to Question #227007 in C++ for Tege

Question #227007

Write C++ program to print pyramid using *.

     

    *

   * * *

  * * * * *

 * * * * * * *

* * * * * * * * *



1
Expert's answer
2021-08-17T16:53:43-0400


#include <iostream>
using namespace std;


int main()
{
    int s, r;


    cout <<"Enter number of rows: ";
    cin >> r;


    for(int i = 1, k = 0; i <= r; ++i, k = 0)
    {
        for(s = 1; s <= r-i; ++s)
        {
            cout <<"  ";
        }


        while(k != 2*i-1)
        {
            cout << "* ";
            ++k;
        }
        cout << endl;
    }    
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS