C++ Online Compiler
Example: Pascal Triangle Pattern in C++ language of Numbers
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Pascal Triangle Pattern in C++ language of Numbers #include <iostream> #include <iomanip> using namespace std; int main() { int r, co = 1, ws, i, j; // r - denotes the number of rows // co - denotes the coefficient value // ws - denotes the white space cout << "-----Enter the number of rows to print the pattern-----\n"; cin >> r; cout << "\n-----This is the pascal triangle pattern-----\n\n"; for (i = 0; i < r; i++) { cout << "\t"; for (ws = 1; ws <= r - i; ws++) { cout << " "; } for (j = 0; j <= i; j++) { if (j == 0 || i == 0) co = 1; else co = co * (i - j + 1) / j; cout << std::setw(4) << co; } cout << "\n"; } return 0; }
8
Output
Clear
ADVERTISEMENTS