60 583
Assignments Done
97,9%
Successfully Done
In April 2018

Answer to Question #23081 in C++ for alfred lontoc

Question #23081
3. Write a program that will display the following pattern, given the value of n.

Example: if n = 4, output

*
**
***
****
Expert's answer
#include <iostream>
using namespace std;

int main()
{
unsigned size;
cout <<"Enter integer n>0 to get a pattern\n";
cin >>size;

int space=2*size-2;
cout <<"For n=" <<size <<":\n";
for ( int astr=1; astr<=size; ++astr )
{
for ( int j=0; j<space; ++j )
{
cout <<" ";
}
for ( int i=0;i<astr; ++i )
{
cout <<"*";
}
cout <<"\n";
space-=2;
}

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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions