# Pyramid pattern using stars or Pyramid star patterns | faceprep

Program to pyramid pattern using stars or Pyramid star patterns are discussed here. For any given number n, print various pyramid star patterns.

## Program to print half pyramid pattern using stars

// C program to print half pyramid pattern using stars
#include <stdio.h>
int main()
{
int i, j,n;
scanf(“%d”,&n);
for(i = 0; i < n; i++)
{
for(j = 0; j <= i; j++)
{
printf(“*”);
}
printf(“\n”);
}
return 0;
}

// C++ program to print half pyramid pattern using stars
#include <iostream>
using namespace std;

int main()
{
int i, j,n;
cin >> n;
for(i = 0; i < n; i++)
{
for(j = 0; j <= i; j++)
{
cout << “*”;
}
cout << endl;
}
return 0;
}

// Java program to print half pyramid pattern using stars
import java.util.*;
public class Main
{
public static void main(String[] args)
{
int n, i, j;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
for(i = 0; i < n; i++)
{
for(j = 0; j <= i; j++)
{
System.out.print(“*”);
}
System.out.print(“\n”);
}
}
}

# Python program to print half pyramid pattern using stars
n = int(input())
for i in range(1, n+1) :
for j in range(1, i+1) :
print(“*”, end=””)
print()

## Program to print inverted half pyramid pattern using stars

// C program to print inverted half pyramid pattern using stars
#include <stdio.h>
int main()
{
int i, j, n, k = 0;
scanf(“%d”,&n);

for(i = n; i >= 1; –i)
{
for(j = 1; j <= i; ++j)
{
printf(“* “);
}
printf(“\n”);
}

return 0;
}

// C++ program to print inverted half pyramid pattern using stars
#include <iostream>
using namespace std;

int main()
{
int i, j, n, k = 0;
cin >> n;

for(i = n; i >= 1; –i)
{
for(j = 1; j <= i; ++j)
{
cout << “* “;
}
cout << endl;
}

return 0;
}

// Java program to print inverted half pyramid pattern using stars
import java.util.*;
public class Main
{
public static void main(String[] args)
{
int n, i, j, k = 0;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
for(i = n; i >= 1; –i)
{
for(j = 1; j <= i; ++j)
{
System.out.print(“* “);
}
System.out.print(“\n”);
}

}
}

# Python program to print inverted half pyramid pattern using stars
n = int(input())
for i in range(n,0,-1):
for j in range(1,i+1,1):
print(“* “, end = “”)
print(“\n”)

## Program to print full pyramid pattern using stars

// C program to print full pyramid pattern using stars
#include <stdio.h>
int main()
{
int i, j, n, k = 0;
scanf(“%d”,&n);

for(i = 1; i <= n; ++i, k = 0)
{
for(j = 1; j <= n – i; ++j)
{
printf(” “);
}

while(k != 2 * i-1)
{
printf(“* “);
++k;
}

printf(“\n”);
}

return 0;
}

// C++ program to print full pyramid pattern using stars
#include <iostream>
using namespace std;

int main()
{
int i, j, n, k = 0;
cin >> n;

for(i = 1; i <= n; ++i, k = 0)
{
for(j = 1; j <= n – i; ++j)
{
cout << ” “;
}

while(k != 2 * i-1)
{
cout << “* “;
++k;
}
cout << endl;
}

return 0;
}

// Java program to print full pyramid pattern using stars
import java.util.*;
public class Main
{
public static void main(String[] args)
{
int n, i, j, k = 0;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
for(i = 1; i <= n; ++i, k = 0)
{
for(j = 1; j <= n – i; ++j)
{
System.out.print(” “);
}

while(k != 2 * i-1)
{
System.out.print(“* “);
++k;
}

System.out.print(“\n”);
}
}
}

# Python program to print full pyramid pattern using stars
n = int(input())
for i in range(1,n+1):
k = 0
for j in range(1,n-i+1):
print(” “, end = “”)

while(k != 2 * i-1):
print(“* “, end = “”)
k = k + 1
print(“\n”)

## Program to print inverted full pyramid pattern using stars

// C program to print inverted full pyramid pattern using stars
#include
int main()
{
int i, j, n, k = 0;
scanf(“%d”,&n);

for(i=n; i>=1; –i)
{
for(j=0; j < n-i; ++j)
printf(” “);

for(j=i; j <= 2*i-1; ++j)
printf(“* “);

for(j=0; j < i-1; ++j)
printf(“* “);

printf(“\n”);
}

return 0;
}

// C++ program to print inverted full pyramid pattern using stars
#include <iostream>
using namespace std;

int main()
{
int i, j, n, k = 0;
cin >> n;

for(i=n; i>=1; –i)
{
for(j=0; j < n-i; ++j)
{
cout << ” “;
}

for(j=i; j <= 2*i-1; ++j)
{
cout << “* “;
}

for(j=0; j < i-1; ++j)
{
cout << “* “;
}

cout << endl;
}

return 0;
}

// Java program to print inverted full pyramid pattern using stars
import java.util.*;
public class Main
{
public static void main(String[] args)
{
int n, i, j, k = 0;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
for(i=n; i>=1; –i)
{
for(j=0; j < n-i; ++j)
System.out.print(” “);

for(j=i; j <= 2*i-1; ++j)
System.out.print(“* “);

for(j=0; j < i-1; ++j)
System.out.print(“* “);

System.out.print(“\n”);
}

}
}

# Python program to print inverted full pyramid pattern using stars
n = int(input())
for i in range(n,1,-1):
for j in range(0, n-i+1):
print(” “, end = “”)

for j in range(i, 2*i-1,1):
print(“* “, end = “”)

for j in range(0, i – 1, 1):
print(“* “, end =””)

print(“\n”);

## Program to print hollow full pyramid pattern using stars

#include <stdio.h>
int main()
{
int n;
scanf(“%d”,&n);
int i, j, k = 0;
for (i = 1; i <= n; i++)
{
for (j = i; j < n; j++) {
printf(” “);
}
while (k != (2 * i – 1)) {
if (k == 0 || k == 2 * i – 2)
printf(“*”);
else
printf(” “);
k++;
;
}
k = 0;
printf(“\n”); // print next row
}
for (i = 0; i < 2 * n – 1; i++) {
printf(“*”);
}
}

#include <iostream>
using namespace std;
void printPattern(int);
int main()
{
int n;
cin >> n;
int i, j, k = 0;
for (i = 1; i <= n; i++)
{
for (j = i; j < n; j++) {
cout << ” “;
}
while (k != (2 * i – 1)) {
if (k == 0 || k == 2 * i – 2)
cout << “*”;
else
cout << ” “;
k++;
;
}
k = 0;
cout << endl; // print next row
}
for (i = 0; i < 2 * n – 1; i++) {
cout << “*”;
}
}

import java.util.*;
public class Main
{
public static void main(String[] args)
{
int n;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int i, j, k = 0;
for (i = 1; i <= n; i++)
{
for (j = i; j < n; j++) {
System.out.print(” “);
}
while (k != (2 * i – 1)) {
if (k == 0 || k == 2 * i – 2)
System.out.print(“*”);
else
System.out.print(” “);
k++;

}
k = 0;
System.out.print(“\n”); // print next row
}
for (i = 0; i < 2 * n – 1; i++) {
System.out.print(“*”);
}
}

}

## Program to print inverted half pyramid pattern

#include <stdio.h>
int main()
{
int n;
scanf(“%d”,&n);
int i, j, k = 0;
for (i = 0; i < n; i++)
{
printf(“* “);
}
for(i=n; i>=1; –i)
{
for(j=0; j < n-i; ++j)
while (k != (2 * i – 1)) {
if (k == 0 || k == 2 * i – 2)
printf(“*”);
else
printf(” “);
k++;

}
k = 0;
printf(“\n”); // print next row
}

}

#include <iostream>
using namespace std;

int main()
{
int n;
cin >> n;
int i, j, k = 0;
for (i = 0; i < n; i++)
{
cout << “* “;
}
for(i=n; i>=1; –i)
{
for(j=0; j < n-i; ++j)
while (k != (2 * i – 1)) {
if (k == 0 || k == 2 * i – 2)
cout << “*”;
else
cout << ” “;
k++;

}
k = 0;
cout << endl; // print next row
}

}

import java.util.*;
public class Main
{
public static void main(String[] args)
{
int n;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int i, j, k = 0;
for (i = 0; i < n; i++)
{
System.out.print(“* “);
}
for(i=n; i>=1; –i)
{
for(j=0; j < n-i; ++j)
while (k != (2 * i – 1))
{
if (k == 0 || k == 2 * i – 2)
System.out.print(“*”);
else
System.out.print(” “);
k++;

}
k = 0;
System.out.print(“\n”); // print next row
}
}
}

Inverted Hollow Full Pyramid

## Program to print inverted hollow full pyramid

#include <stdio.h>
int main()
{
int n;
scanf(“%d”, &n);
int i, j;
for (i = 1; i <= n; i++) {
for (j = 1; j < i; j++) {
printf(” “);
}

for (j = 1; j <= (n * 2 – (2 * i – 1)); j++) {

if (i == 1 || j == 1 || j == (n * 2 – (2 * i – 1))) {
printf(“*”);
} else {
printf(” “);
}
}
printf(“\n”);
}
}

#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int i, j;
for (i = 1; i <= n; i++) {
for (j = 1; j < i; j++) {
cout << ” “;
}

for (j = 1; j <= (n * 2 – (2 * i – 1)); j++) {

if (i == 1 || j == 1 || j == (n * 2 – (2 * i – 1))) {
cout << “*”;
} else {
cout << ” “;
}
}
cout << endl;
}
}

import java.util.*;
public class Main
{
public static void main(String[] args)
{
int n;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int i, j;
for (i = 1; i <= n; i++) {
for (j = 1; j < i; j++) {
System.out.print(” “);
}

for (j = 1; j <= (n * 2 – (2 * i – 1)); j++) {

if (i == 1 || j == 1 || j == (n * 2 – (2 * i – 1))) {
System.out.print(“*”);
} else {
System.out.print(” “);
}
}
System.out.print(“\n”);
}
}
}

Output:

Half pyramid pattern:

Inverted half pyramid pattern:

Full pyramid pattern:

Inverted full pyramid pattern:

Hollow full pyramid:

Inverted hollow half pyramid pattern:

Inverted Hollow Full Pyramid Pattern: