C++ Program to print Number Triangle

Share on facebook
Share on twitter
Share on linkedin
Share on twitter
Share on tumblr

In this Basic C++ Program, we will have a look at how to write a c++ program to print number triangle. Like the alphabet triangle, we can write a C ++ program to print a number triangle. The numeric triangle can be printed in various ways.

Example of Number Triangle

      1
     121
    12321
   1234321
  123454321
 12345654321

Print Number Triangle in C++

#include <iostream>

using namespace std;

int main() {

  int i, j, k, l, n;

  cout << "Enter the Range=";

  cin >> n;

  for (i = 1; i <= n; i++) {

    for (j = 1; j <= n - i; j++) {

      cout << " ";

    }

    for (k = 1; k <= i; k++) {

      cout << k;

    }

    for (l = i - 1; l >= 1; l--) {

      cout << l;

    }

    cout << "\n";

  }

  return 0;

}

Output:

      1
     121
    12321
   1234321
  123454321
 12345654321

Leave a Comment

Your email address will not be published. Required fields are marked *