Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create pramid pattern #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
48 changes: 48 additions & 0 deletions cpp/pramid pattern
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// C++ implementation to print the following
// pyramid pattern
#include <bits/stdc++.h>
using namespace std;

// function to print the following pyramid pattern
void printPattern(int n)
{
int j, k = 0;

// loop to decide the row number
for (int i=1; i<=n; i++)
{
// if row number is odd
if (i%2 != 0)
{
// print numbers with the '*' sign in
// increasing order
for (j=k+1; j<k+i; j++)
cout << j << "*";
cout << j++ << endl;

// update value of 'k'
k = j;
}

// if row number is even
else
{
// update value of 'k'
k = k+i-1;

// print numbers with the '*' in
// decreasing order
for (j=k; j>k-i+1; j--)
cout << j << "*";
cout << j << endl;
}
}
}

// Driver program to test above
int main()
{
int n = 5;
printPattern(n);
return 0;
}