Answer to Question #285037 in C++ for Jeanelle

Question #285037

 

1.      Using the looping statement. Create a program that will display the following:

 

 

 

A.  *

***

****

****

***

*

 

 

B.     @@@@@@@

@

@

        @

        @@@@@@@

1
Expert's answer
2022-01-05T16:25:03-0500


//Solution [a]
using namespace std;
int main()
{
	int i,L,j;
	L=5;
	
	for(i=1;i<=L;i=i+2)
	{
		for(j=1;j<=i;j++) cout<<"*";	cout<<endl;
	}
	for(i=L;i>=1;i=i-2)
	{
		for(j=1;j<=i;j++) cout<<"*";	cout<<endl;
	}
}



//Solution [b]
using namespace std;

int main()
{
	int j,L=5;
	
	for(j=1;j<=L;j++) cout<<"@";
	cout<<endl;
	for(j=1;j<=3;j++) cout<<"@"<<endl;
	for(j=1;j<=L;j++) cout<<"@";
}

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