50. Program to display the following output using loop.

Chapter 6: 

Looping Structures

Programming Exercise

Problem # 50:

Write a program to display the following output using loop:
                                 &
                             &     &
                          &           &
                       &                 &
                    &                       &
                 &                              &
              &                                    &
           &                                          &
        &                                                 &
    &&&&&&&&&&&&&&&&&&&

Solution:

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    int count=9;
    for(int i=9;i>=1;i--)
    {
        for(int j=18;j>=1;j--)
        {
            if(j==count||i==j)
            cout<<"&";
            else
            cout<<" ";
        }
        cout<<endl;
        count++;  
    }
    for(int k=1;k<=19;k++)
    cout<<"&";
    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:
49. Program to display the following output using loop.

Comments