Repetition and Nested Loop Structures

Write a C++ program that prompts the user to enter a number and then prints the “bow” pattern shown below.

*****
****
***
**
*
*
**
***
****
*****

Hint: use nested FOR loops to generate the pattern

~I am stuck on how to flip the top triangle to make the bow. Help...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  #include <iostream>

using namespace std;

int main() {

//Declare

  int N;
  N=5;
  
// Loop


 for (int i = 5; i <= N+1; i++) //stuck here
{
 for (int j = i; j <= i; j++)
{
  cout << "*";
}
 cout << endl;
{
 
}

  for (int i = 1; i <= N; i++) //this triangle is complete
{
  for (int j = 1; j <= i; j++)
{
  cout << "*";
}
  cout << endl;
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>

int main()
{
    int n = 12 ;

    // TO DO: accept the value of n from user input

    for( int row = 0 ; row < n ; ++row ) // for each of the first n rows
    {
        const int nstars = n - row ; // number of stars in this row

        // print 'nstars' stars
        for( int col = 0 ; col < nstars ; ++col ) std::cout << '*' ;
        std::cout << '\n' ;
    }

    for( int row = 0 ; row < n ; ++row ) // for each of the second set of n rows
    {
        const int nstars = row+1 ; // number of stars in this row

        // print 'nstars' stars
        for( int col = 0 ; col < nstars ; ++col ) std::cout << '*' ;
        std::cout << '\n' ;
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
   int N = 5;
   for ( int i = N; i >= -N; i--)
   {
      for ( int j = 1; j <= abs( i ); j++ ) cout << "*";
      if ( i ) cout << '\n';
   }
}
*****
****
***
**
*
*
**
***
****
*****
Topic archived. No new replies allowed.