43. Program to print the following output using loop.

Chapter 6: 

Looping Structures

Programming Exercise

Problem # 43:

Write a program to print the following output using loop:
    BBBBBBBBB
    . BBBBBBB
    . .  BBBBB
    . . .  BBB
    . . . .  B

Solution:

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    int i, k, m, l;
  
    for(i=0;i<=4;i++)
    {
      
        for(k=i;k>0;k--)
        {
        cout<<".";  
        }
      
        for(l=i;l<9-i;l++)
        {
        cout<<"B";  
        }
        cout<<"\n";      
    }
    getch();
}

Output:

Chapter 6, Coding tutorial, Computer Science, CPP Basics, Exercise Solution, IT Series, Looping Structures, Object Oriented Programming using C++, Programming for beginners, Programming Tutorial

Let me know in the comment section if you have any question.

Previous Post:
42. Program to print the following output using loop.

Comments