From 9fa3061154d98ee568ee065fcd19568e6dda59b4 Mon Sep 17 00:00:00 2001 From: Ishika <96570918+Ishika0-0@users.noreply.github.com> Date: Fri, 6 Oct 2023 17:17:35 +0530 Subject: [PATCH] Create Triangle_pattern.cpp --- Triangle_pattern.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Triangle_pattern.cpp diff --git a/Triangle_pattern.cpp b/Triangle_pattern.cpp new file mode 100644 index 0000000..e4f530f --- /dev/null +++ b/Triangle_pattern.cpp @@ -0,0 +1,37 @@ +// C++ code to demonstrate star pattern +#include +using namespace std; + +// Function to demonstrate printing pattern +void tri(int n) +{ + // Number of spaces + int i, j, k = n; + // Outer loop to handle number of rows + + // n in this case + + for (i = 1; i <= n; i++) { + // Inner loop for columns + + for (j = 1; j <= n; j++) { + // Condition to print star pattern + + if (j >= k) + cout << "* "; + else + cout << " "; + } + k--; + cout << "\n"; + } +} +// Driver Code + +int main() +{ + int n = 5; + // Function Call + tri(n); + return 0; +}