EmSAT Achieve Exam  >  EmSAT Achieve Notes  >  C++ for EmSAT Achieve  >  Code: Pascal's Triangle

Code: Pascal's Triangle | C++ for EmSAT Achieve PDF Download

Code: Pascal`s Triangle | C++ for EmSAT Achieve

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 | C++ for EmSAT Achieve is a part of the EmSAT Achieve Course C++ for EmSAT Achieve.
All you need of EmSAT Achieve at this link: EmSAT Achieve
70 videos|45 docs|15 tests

Top Courses for EmSAT Achieve

70 videos|45 docs|15 tests
Download as PDF
Explore Courses for EmSAT Achieve exam

Top Courses for EmSAT Achieve

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

shortcuts and tricks

,

study material

,

Summary

,

Code: Pascal's Triangle | C++ for EmSAT Achieve

,

pdf

,

MCQs

,

ppt

,

Extra Questions

,

practice quizzes

,

video lectures

,

Previous Year Questions with Solutions

,

Objective type Questions

,

Code: Pascal's Triangle | C++ for EmSAT Achieve

,

Exam

,

Free

,

Sample Paper

,

past year papers

,

Code: Pascal's Triangle | C++ for EmSAT Achieve

,

Semester Notes

,

Important questions

,

Viva Questions

,

mock tests for examination

;