Skip to content

Instantly share code, notes, and snippets.

@lakshyaraj2006
Created January 4, 2025 02:12
Show Gist options
  • Select an option

  • Save lakshyaraj2006/12c1ed38dc43bfa5302e249e8698110c to your computer and use it in GitHub Desktop.

Select an option

Save lakshyaraj2006/12c1ed38dc43bfa5302e249e8698110c to your computer and use it in GitHub Desktop.
A start pattern using c++ language
#include <iostream>
using namespace std;
void pattern1(int n)
{
int space = 0;
for (int i = n; i >= 1; i--)
{
// stars
for (int j = 1; j <= i; j++)
{
cout << "*";
}
// space
for (int j = 0; j < space; j++)
{
cout << " ";
}
// stars
for (int j = i; j >= 1; j--)
{
cout << "*";
}
cout << endl;
space += 2;
}
}
void pattern2(int n)
{
int space = 2 * (n - 1);
for (int i = 1; i <= n; i++)
{
// stars
for (int j = 1; j <= i; j++)
{
cout << "*";
}
// space
for (int j = 0; j < space; j++)
{
cout << " ";
}
// stars
for (int j = i; j >= 1; j--)
{
cout << "*";
}
cout << endl;
space -= 2;
}
}
int main()
{
int n;
cin >> n;
pattern1(n);
pattern2(n);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment