From 5e8dbedf1a0883481b49870ffceb646ce2d1dd7a Mon Sep 17 00:00:00 2001 From: Kavya Jain <89743157+ikavyajain@users.noreply.github.com> Date: Tue, 12 Oct 2021 15:43:11 +0530 Subject: [PATCH 1/3] Create Pattern_Pascal'sTriangle.cpp :) --- Pattern/Pattern_Pascal'sTriangle.cpp | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Pattern/Pattern_Pascal'sTriangle.cpp diff --git a/Pattern/Pattern_Pascal'sTriangle.cpp b/Pattern/Pattern_Pascal'sTriangle.cpp new file mode 100644 index 0000000..e8b6963 --- /dev/null +++ b/Pattern/Pattern_Pascal'sTriangle.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; + +int main() +{ + int rows, coef = 1; // coef is a counter variable to perform the pascal's triangle function + + cout << "Enter number of rows: "; + cin >> rows; // No. of rows the user wants to input + + for(int i = 0; i < rows; i++) + { + for(int space = 1; space <= rows-i; space++) + cout <<" "; // Adding spaces till columns are less than or equal to the (no. of rows - i) + + for(int j = 0; j <= i; j++) + { + if (j == 0 || i == 0) // Base case + coef = 1; + else + coef = coef*(i-j+1)/j; + + cout << coef << " "; + } + cout << endl; // To skip to the other row + } + + return 0; +} From 26214832f46ef51c0bf719359a05ce1d1c646249 Mon Sep 17 00:00:00 2001 From: Kavya Jain <89743157+ikavyajain@users.noreply.github.com> Date: Tue, 12 Oct 2021 15:44:44 +0530 Subject: [PATCH 2/3] Delete Pattern_Pascal'sTriangle.cpp --- Pattern/Pattern_Pascal'sTriangle.cpp | 29 ---------------------------- 1 file changed, 29 deletions(-) delete mode 100644 Pattern/Pattern_Pascal'sTriangle.cpp diff --git a/Pattern/Pattern_Pascal'sTriangle.cpp b/Pattern/Pattern_Pascal'sTriangle.cpp deleted file mode 100644 index e8b6963..0000000 --- a/Pattern/Pattern_Pascal'sTriangle.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include -using namespace std; - -int main() -{ - int rows, coef = 1; // coef is a counter variable to perform the pascal's triangle function - - cout << "Enter number of rows: "; - cin >> rows; // No. of rows the user wants to input - - for(int i = 0; i < rows; i++) - { - for(int space = 1; space <= rows-i; space++) - cout <<" "; // Adding spaces till columns are less than or equal to the (no. of rows - i) - - for(int j = 0; j <= i; j++) - { - if (j == 0 || i == 0) // Base case - coef = 1; - else - coef = coef*(i-j+1)/j; - - cout << coef << " "; - } - cout << endl; // To skip to the other row - } - - return 0; -} From 69f8a07bfa147b54a9f9073e499c78450568a1dc Mon Sep 17 00:00:00 2001 From: Kavya Jain <89743157+ikavyajain@users.noreply.github.com> Date: Tue, 12 Oct 2021 15:45:35 +0530 Subject: [PATCH 3/3] Create Pattern_Pascal'sTriangle.cpp :) --- Pattern/Pattern_Pascal'sTriangle.cpp | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Pattern/Pattern_Pascal'sTriangle.cpp diff --git a/Pattern/Pattern_Pascal'sTriangle.cpp b/Pattern/Pattern_Pascal'sTriangle.cpp new file mode 100644 index 0000000..e8b6963 --- /dev/null +++ b/Pattern/Pattern_Pascal'sTriangle.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; + +int main() +{ + int rows, coef = 1; // coef is a counter variable to perform the pascal's triangle function + + cout << "Enter number of rows: "; + cin >> rows; // No. of rows the user wants to input + + for(int i = 0; i < rows; i++) + { + for(int space = 1; space <= rows-i; space++) + cout <<" "; // Adding spaces till columns are less than or equal to the (no. of rows - i) + + for(int j = 0; j <= i; j++) + { + if (j == 0 || i == 0) // Base case + coef = 1; + else + coef = coef*(i-j+1)/j; + + cout << coef << " "; + } + cout << endl; // To skip to the other row + } + + return 0; +}