# Pyramid pattern printing using numbers or Pyramid number patterns | faceprep

Program to print pyramid pattern printing using numbers or Pyramid number patterns is discussed here. Given a number n, the various patterns of pyramids using numbers are produced as output.

## Program to print half pyramid pattern using numbers

/* C program – Half Pyramid Pattern Printing using numbers */
#include
int main()
{
int i, j,n;
scanf(“%d”,&n);
for(i = 1; i <= n; i++)
{
for(j = 1; j <= i; j++)
{
printf(“%d “,j);
}
printf(“\n”);
}
return 0;
}

// C++ program – Half Pyramid Pattern Printing using numbers
#include <iostream>
using namespace std;

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

/* Java program – Half Pyramid Pattern Printing using numbers */

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(j + ” “);
}
System.out.println();
}
}
}

# Python program – Half Pyramid Pattern Printing using numbers
n = int(input())
for i in range(1,n+1):
for j in range(1,i+1):
print(j, end = ” “)
print()

## Program to print inverted half pyramid pattern printing using numbers

/* C program – Pyramid Pattern Printing using numbers */
#include
int main()
{
int i, j,n;
scanf(“%d”,&n);
for(i = 1; i <= n; i++)
{
for(j = i; j <= n; j++)
{
printf(“%d “,j);
}
printf(“\n”);
}
return 0;
}

// C++ program – Pyramid Pattern Printing using numbers
#include <iostream>
using namespace std;

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

/* Java program – Pyramid Pattern Printing using numbers */

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 = i; j <= n; j++)
{
System.out.print(j + ” “);
}
System.out.println();
}
}
}

# Python program – Pyramid Pattern Printing using numbers
n = int(input())
for i in range(1,n+1):
for j in range(i,n+1):
print(j, end = ” “)
print()

## Program to print full pyramid using numbers

/* C program – Full Pyramid Pattern Printing using numbers */
#include
int main()
{
int i, j, n, count = 0, count1 = 0, k = 0;
scanf(“%d”,&n);
for(i = 1; i <= n; ++i)
{
for(j = 1; j <= n-i; ++j)
{
printf(” “);
++count;
}

while(k != 2*i-1)
{
if (count <= n-1)
{
printf(“%d “, i+k);
++count;
}
else
{
++count1;
printf(“%d “, (i+k-2*count1));
}
++k;
}
count1 = count = k = 0;

printf(“\n”);
}
return 0;
}

/* C program – Full Pyramid Pattern Printing using numbers */
#include
int main()
{
int i, j, n, count = 0, count1 = 0, k = 0;
scanf(“%d”,&n);
for(i = 1; i <= n; ++i)
{
for(j = 1; j <= n-i; ++j)
{
printf(” “);
++count;
}

while(k != 2*i-1)
{
if (count <= n-1)
{
printf(“%d “, i+k);
++count;
}
else
{
++count1;
printf(“%d “, (i+k-2*count1));
}
++k;
}
count1 = count = k = 0;

printf(“\n”);
}
return 0;
}

/* Java program – Full Pyramid Pattern Printing using numbers */

import java.util.*;
public class Main
{
public static void main(String[] args)
{
int i, j, n, count = 0, count1 = 0, k = 0;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();

for(i = 1; i <= n; ++i)
{
for(j = 1; j <= n-i; ++j)
{
System.out.print(” “);
++count;
}

while(k != 2*i-1)
{
if (count <= n-1)
{
System.out.print(i+k + ” “);
++count;
}
else
{
++count1;
System.out.print((i+k-2*count1) + ” “);
}
++k;
}
count1 = count = k = 0;

System.out.println();
}
}
}

# Python program – Full Pyramid Pattern Printing using numbers
n = int(input())
count = count1 = k = 0
for i in range(1,n+1):
for j in range(1,n-i+1):
print(” “, end = ” “)
count = count + 1
while(k != 2*i-1):
if (count <= n-1):
print(i+k, end = ” “)
count = count + 1
else:
count1 = count1 + 1
print((i+k-2*count1), end = ” “)
k = k + 1
count1 = count = k = 0

print()

## Program to print hollow half pyramid pattern using numbers

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

/* C++ program print hollow half pyramid pattern using numbers */
#include <iostream>
using namespace std;

int main()
{
int i, j, n, k = 0;
cin >> n;
for(i = 1; i <= n; i++)
{
for(j = 1; j <= i; j++)
{
if (j == 1 || j == i || i == n)
cout << j;
else
cout << ” “;
}
cout << endl;
}
return 0;
}

/* Java program print hollow half pyramid pattern using numbers */
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 = 1; i <= n; i++)
{
for(j = 1; j <= i; j++)
{
if (j == 1 || j == i || i == n)
System.out.print(j);
else
System.out.print(” “);
}
System.out.println();
}
}
}

# Python program print hollow half pyramid pattern using numbers */
n = 5
for i in range(1, n+1):
for j in range(1, i+1):
if(j == 1 or j == i or i == n):
print(j, end = “”)
else:
print(” “, end = “”)
print()

## Program to print hollow inverted half pyramid pattern using numbers

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

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

int main()
{
int i, j, n, k = 0;
cin >> n;
for(i = 1; i <= n; i++)
{
for(j = i; j <= n; j++)
{
if (i == 1 || j == i || j == n)
cout << j;
else
cout << ” “;
}
cout << endl;
}
return 0;
}

/* Java program print hollow half pyramid pattern using numbers */
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 = 1; i <= n; i++)
{
for(j = i; j <= n; j++)
{
if (i == 1 || j == n || j == i)
System.out.print(j);
else
System.out.print(” “);
}
System.out.println();
}
}
}

# Python program to print inverted hollow half pyramid pattern using numbers
n = int(input())
for i in range(1, n+1):
for j in range(i, n+1):
if(i == 1 or j == i or j == n):
print(j, end = “”)
else:
print(” “, end = “”)
print()

## Program to print hollow inverted full pyramid pattern using numbers

/* C program to print hollow full pyramid pattern using numbers */
#include <stdio.h>
int main()
{
int i, j, n;
printf(“Enter value of n : “);
scanf(“%d”, &n);
for(i = 1; i <= n; i++)
{
for(j = i; j < n; j++)
{
printf(” “);
}
for(j = 1; j <= i; j++)
{
if(j == 1 || i == n)
{
printf(“%d “, j);
}
else
{
printf(” “);
}
}
for(j = 1; j < i; j++)
{
if(j == i-1 && j < n-1)
{
printf(“%d”, j+1);
}
else
{
printf(” “);
}
}
printf(“\n”);
}
return 0;
}

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

int main()
{
int i, j, n;
cout << “Enter value of n : “;
cin >> n;
for(i = 1; i <= n; i++)
{
for(j = i; j < n; j++)
{
cout << ” “;
}
for(j = 1; j <= i; j++)
{
if(j == 1 || i == n)
{
cout << j << ” “;
}
else
{
cout << ” “;
}
}
for(j = 1; j < i; j++)
{
if(j == i-1 && j < n-1)
{
cout << j+1;
}
else
{
cout << ” “;
}
}
cout << endl;
}
return 0;
}

/* Java program print hollow full pyramid pattern using numbers */
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 = 1; i <= n; i++)
{
for(j = i; j < n; j++)
{
System.out.print(” “);
}
for(j = 1; j <= i; j++)
{
if(j == 1 || i == n)
{
System.out.print(j + ” “);
}
else
{
System.out.print(” “);
}
}
for(j = 1; j < i; j++)
{
if(j == i-1 && j < n-1)
{
System.out.print(j+1);
}
else
{
System.out.print(” “);
}
}
System.out.print(“\n”);
}
}
}

Output:

Half Pyramid Pattern:

Full Pyramid Pattern:

Inverted Half Pyramid Pattern:

Hollow Half Pyramid Pattern:

Hollow Inverted Half Pyramid Pattern:

Hollow Full Pyramid pattern: