Answer to Question #319800 in C++ for Zaki

Question #319800

Write a C++ program that asks the user to enter a number N .After that, print N lines using asterisk (*) in a


triangle shape as shown below;


Sample Input:


Enter number of lines to print: 6

1
Expert's answer
2022-03-28T13:52:21-0400
#include<iostream>
using namespace std;
int main()
{
    int i, space, rowSize, k=0;
    cout<<"Enter number of lines to print: ";
    cin>>rowSize;
    
    for(i=1; i<=rowSize; i++)
    {
        for(space=1; space<=(rowSize-i); space++)
            cout<<"  ";
        while(k!=(2*i-1))
        {
            cout<<"* ";
            k++;
        }
        k=0;
        cout<<endl;
    }
    cout<<endl;
	   cin>>rowSize;


    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
New on Blog