Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Triangle_pattern.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// C++ code to demonstrate star pattern
#include <iostream>
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;
}