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

*
**
***
****
1
Expert's answer
2013-01-29T08:25:05-0500
#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 the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS