42. Program to print the following output using loop.

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();
}

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:
41. Program that uses nested for loops to display the following lines.

Comments