[Solved] Character Pattern 8 with C++

Character Pattern 8: Write a program to generate the following pattern.

*********

b******* b

bb***** bb

bbb***bbb

bbbb*bbbb

Input and Output Format:

Input consists of a single integer that corresponds to n, the number of rows. n is always an odd number.

Sample Input :

5

Sample Output :

*********

b******* b

bb***** bb

bbb***bbb

bbbb*bbbb

Solution

#include <iostream>
using namespace std;
int main()
{
    int n, i, j;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        for (j = 1; j < n * 2; j++)
        {
            if (i >= j || j >= n * 2 - i)
                printf("b");
            else
                printf("*");
        }
        printf("\n");
    }
    return (0);
}

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

📌 Nodejs and Android 😎
📌 Java

Articles: 444

Leave a Reply

Your email address will not be published. Required fields are marked *