49. Program to display the following output using loop.

Chapter 6: 

Looping Structures

Programming Exercise

Problem # 49:

Write a program to display the following output using loop:
    1234567654321
    123456  654321
    12345      54321
    1234          4321
    123              321
    12                  21
    1                      1

Solution:

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    int i, j, k, l, m, n;
  
    for(i=7, n=7;i>=1;i--,n--)
    {
        for(j=1;j<=i;j++)
        {
          
            if(j==7)
            break;
            cout<<j;
        }
        for(m=i;m<=12-i;m++)
        {
            cout<<" ";  
        }
      
        for(l=n;l>=1;l--)
        {
            cout<<l;
          
        }
        cout<<endl;
    }
}

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:
48. Program to display the following output using while loop.

Comments