Advanced In this exercise, you create a program that uses two nested loops to di
ID: 3594746 • Letter: A
Question
Advanced In this exercise, you create a program that uses two nested loops to display two different patterns of asterisks: Pattern 1 contains nine rows of asterisks as follows: nine asterisks, eight asterisks, sever asterisks, six asterisks, five asterisks, four asterisks, three asterisks, two asterisks, and one asterisk (see Figure 8-2). Pattern 2 contains nine rows of asterisks as follows: one asterisk, two asterisks, three asterisks, four asterisks, five asterisks, six asterisks, seven asterisks, eight asterisks, and nine asterisks Use whatever type of loops you feel would be most appropriate Create a new project named Advanced27 Project. Enter your C++ instructions into a source file named Advanced27.cpp a. b. Save and then run the program. Display the asterisks using the first pattern, and then display them using the second pattern Figure 8-2 Pattern 2 is just the opposite: it starts out with 1 asterisk on line 1 and ends with 9 asterisks on line 9Explanation / Answer
#include<iostream>
using namespace std;
main()
{
int i,n=9,j;
// for pattern 1
for(i=n;i>0;i--)
{
for(j=0;j<i;j++)
cout << "*";
cout << endl;
}
// for pattern 2
for(i=0;i<n;i++)
{
for(j=0;j<i;j++)
cout << "*";
cout << endl;
}
}
/*SAMPLE OUTPUT
*********
********
*******
******
*****
****
***
**
*
*
**
***
****
*****
******
*******
********
*/
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.