C++ Program for triangular pattern (mirror image around 0)

Given with the positive value n and the task is to generate the triangular pattern i.e. mirror image of the printed numbers and display the result

Example

Input-: n = 6
Output-:

Input-: n = 3
Output-:

Approach used in the below program is as follows

  • Input the value of n as a positive integer
  • Traverse one loop i for the number of rows in a pattern i.e. n
  • Traverse one loop j for the number of spaces in a pattern
  • Traverse another loop for the digits in a pattern

Algorithm

START
Step 1-> declare function to print mirror image of triangular pattern
   void print_mirror(int n)
   declare and set int temp = 1 and temp2 = 1
      Loop for int i = 0 and i  i and j—
            print space
         End
         Loop For int k = 1 and k  In main()
   Declare int n = 6
   print_mirror(n)
STOP

Example

#include 
using namespace std;
//function to print mirror image of triangular pattern
void print_mirror(int n) {
   int temp = 1, temp2 = 1;
   for (int i = 0; i  i; j--) {
         cout 

Output

Updated on: 2020-07-09T08:23:06+05:30

386 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements