Software Development Exam  >  Software Development Notes  >  Basics of C++  >  Code: Pascal's Triangle

Code: Pascal's Triangle

Code: Pascal`s Triangle

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;

}

The document Code: Pascal's Triangle is a part of the Software Development Course Basics of C++.
All you need of Software Development at this link: Software Development
Explore Courses for Software Development exam
Get EduRev Notes directly in your Google search
Related Searches
Code: Pascal's Triangle, pdf , Sample Paper, study material, Viva Questions, Free, Extra Questions, shortcuts and tricks, Objective type Questions, ppt, MCQs, past year papers, Summary, practice quizzes, Code: Pascal's Triangle, Code: Pascal's Triangle, Semester Notes, video lectures, Important questions, Previous Year Questions with Solutions, mock tests for examination, Exam;