Chapter 6:
Looping Structures
Programming Exercise
Problem # 42:
Write a program to print the following output using loop:
#####*#####
####*#*####
###*###*###
##*#####*##
#*#######*#
*#########*
Solution:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int count=6;
for(int i=6;i>=1;i--)
{
for(int j=11;j>=1;j--)
{
if(j==count||i==j)
cout<<"*";
else
cout<<"#";
}
cout<<endl;
count++;
}
getch();
}
#include<conio.h>
using namespace std;
int main()
{
int count=6;
for(int i=6;i>=1;i--)
{
for(int j=11;j>=1;j--)
{
if(j==count||i==j)
cout<<"*";
else
cout<<"#";
}
cout<<endl;
count++;
}
getch();
}
Output:
Let me know in the comment section if you have any question.
Previous Post:
41. Program that uses nested for loops to display the following lines.
Comments
Post a Comment