Pascals Triangle Pattern Printing (With C++ Code) | Pattern Printing Programs

Pascal’s triangle is a triangular array of the binomial coefficients. In this tutorial we will study and understand the pascals triangle pattern printing program code with the help of dry running and visual diagrams.. Later we will also write a program to print this pattern in C++ Programming Language.

C++ Program for Pascals Triangle Pattern –
#include<iostream>

using namespace std;

void PascalsTriangle(int n) {

  for (int i = 1; i <= n; i++) {
    int coef = 1;
    for (int k = n - i; k > 0; k--) {
      cout << " ";
    }
    for (int j = 1; j <= i; j++) {
      cout << coef << " ";
      coef = coef * (i - j) / j;

    }
    cout << endl;
  }
}

int main() {
  int num;
  cout << "Enter number of levels of the pattern :" << endl;
  cin >> num;
  PascalsTriangle(num);

  return 0;
}
YouTube video tutorial –

Leave a Reply

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