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();
}
#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:
Let me know in the comment section if you have any question.
Previous Post:
42. Program to print the following output using loop.
Comments
Post a Comment