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; +}