# Palindrome pyramid pattern printing using numbers | faceprep

Program to print palindrome pyramid pattern using numbers is discussed here. Given a number n, the task is to print a palindrome pyramid containing n number of rows.

##### Palindrome half pyramid pattern using numbers

Input: 5 (number of rows)

Output:

1
1   2   1
1   2   3   2   1
1   2   3   4   3   2   1
1   2   3   4   5   4   3   2   1

## Program to print palindrome pyramid pattern using numbers

/* C program for Palindrome pyramid pattern printing using numbers */
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,j,k,l,n;
printf(“Enter the number of rows : “);
scanf(“%d”,&n);
for(i = 1; i <= n; i++)
{
for(k = 1; k <= i; k++)
{
printf(“%d “,k);
}
for(l = i-1; l >= 1; l–)
{
printf(“%d “,l);
}
printf(“\n”);
}
return 0;
}

/* C++ program for Palindrome pyramid pattern printing using numbers */
#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
int i,j,k,l,n;
cout << “Enter the number of rows : “;
cin >> n;
for(i = 1; i <= n; i++)
{
for(k = 1; k <= i; k++)
{
cout << k << ” “;
}
for(l = i-1; l >= 1; l–)
{
cout << l << ” “;
}
cout << endl;
}
return 0;
}

/* Java program for Palindrome pyramid pattern printing using numbers */
import java.util.*;
public class Main {

public static void main(String[] args) {
int n, k, l, i;
Scanner sc = new Scanner(System.in);
System.out.print(“\nEnter the number of rows : “);
n = sc.nextInt();
System.out.print(“\n”);
for(i = 1; i <= n; i++)
{
for(k = 1; k <= i; k++)
{
System.out.print(k + ” “);
}
for(l = i-1; l >= 1; l–)
{
System.out.print(l + ” “);
}
System.out.print(“\n”);
}
}
}

# Python program for Palindrome pyramid pattern printing using numbers
n = int(input(“Enter the number of rows : “))
for i in range(1, n+1):
for k in range(1, i+1):
print(k, end = ” “)

for l in range(i-1, 0, -1):
print(l , end = ” “)

print(“\n”)

Output:

##### Palindrome half pyramid pattern using alphabets

Input: 5 (number of rows)

Output:

A
A   B   A
A   B   C   B   A
A   B   C   D   C   B   A
A   B   C   D   E   D   C   B   A

## Program to print palindrome pyramid pattern using alphabets

/* C program for Palindrome pyramid pattern printing using alphabets */
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,j,k,l,n;
printf(“Enter the number of rows : “);
scanf(“%d”,&n);
for(i = 1; i <= n; i++)
{
for(k = 1; k <= i; k++)
{
printf(“%c “,(k + 65 – 1));
}
for(l = i-1; l >= 1; l–)
{
printf(“%c “,(l + 65 – 1));
}
printf(“\n”);
}
return 0;
}

/* C++ program for Palindrome pyramid pattern printing using alphabets */
#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
int i,j,k,l,n;
cout << “Enter the number of rows : “;
cin >> n;
for(i = 1; i <= n; i++)
{
for(k = 1; k <= i; k++)
{
cout << char(k+65-1) << ” “;
}
for(l = i-1; l >= 1; l–)
{
cout << char(l+65-1) << ” “;
}
cout << endl;
}
return 0;
}

/* Java program for Palindrome pyramid pattern printing using alphabets */
import java.util.*;
public class Main {

public static void main(String[] args) {
int n, k, l, i;
Scanner sc = new Scanner(System.in);
System.out.print(“\nEnter the number of rows : “);
n = sc.nextInt();
System.out.print(“\n”);
for(i = 1; i <= n; i++)
{
for(k = 1; k <= i; k++)
{
System.out.print((char)(k+65-1) + ” “);
}
for(l = i-1; l >= 1; l–)
{
System.out.print((char)(l+65-1) + ” “);
}
System.out.print(“\n”);
}
}
}

# Python program for Palindrome pyramid pattern printing using alphabets
n = int(input(“Enter the number of rows : “))
for i in range(1, n+1):
for k in range(1, i+1):
print(chr(k+65-1), end = ” “)

for l in range(i-1, 0, -1):
print(chr(l+65-1) , end = ” “)

print(“\n”)

Output:

##### Palindrome pyramid pattern using numbers

Input: 5(number of rows)

Output:

1
1   2   1
1   2   3   2   1
1   2   3   4   3   2   1
1   2   3   4   5   4   3    2   1

## Program to print palindrome pyramid pattern using numbers

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

for (j=1; j<=n-i; j++)
printf(” “);

for (j=1,k=2*i-1; j<=2*i-1; j++,k–)
{
if (j <= k)
printf(“%d”, j);
else
printf(“%d”, k);
}
printf(“\n”);

printf(” “);

}
return 0;
}

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

for (j=1; j<=n-i; j++)
cout << ” “;

for (j=1,k=2*i-1; j<=2*i-1; j++,k–)
{
if (j <= k)
cout << j;
else
cout << k;
}
cout << endl;

cout << ” “;

}
return 0;
}

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

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

for (j=1,k=2*i-1; j<=2*i-1; j++,k–)
{
if (j <= k)
System.out.print(j);
else
System.out.print(k);
}
System.out.print(“\n”);

System.out.print(” “);

}

}
}

Output:

##### Palindrome pyramid pattern using numbers and stars

Input: 7

Output:

*******1********
*******2*2*******
******3*3*3******
*****4*4*4*4*****
****5*5*5*5*5****
***6*6*6*6*6*6***

## Program to print palindrome pyramid pattern using numbers & stars

#include<stdio.h>
int main()
{
int n, i, j, space, count = 1, num = 0, star = 8;
scanf(“%d”, &n);
space = n;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= star; j++)
if(i + j <= star + 1)
printf(“*”);
num++;
for (j = 1; j <= i; j++)
{
printf(“%d”, num);
if (i > 1 && count < i)
{
printf(“*”);
count++;
}
}
for (j = 1; j <= star; j++)
if(i + n <= j + n)
printf(“*”);
printf(“\n”);
space–;
count = 1;
}
return 0;
}

#include<iostream>
using namespace std;
int main()
{
int n, i, j, space, count = 1, num = 0, star = 8;
cin >> n;
space = n;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= star; j++)
if(i + j <= star + 1)
cout << “*”;
num++;
for (j = 1; j <= i; j++)
{
cout << num;
if (i > 1 && count < i)
{
cout << “*”;
count++;
}
}
for (j = 1; j <= star; j++)
if(i + n <= j + n)
cout << “*”;
cout << “\n”;
space–;
count = 1;
}
return 0;
}

import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int i, j, space, count = 1, num = 0, star = 8;
int n = sc.nextInt();
space = n;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= star; j++)
if(i + j <= star + 1)
System.out.print(“*”);
num++;
for (j = 1; j <= i; j++)
{
System.out.print(num);
if (i > 1 && count < i)
{
System.out.print(“*”);
count++;
}
}
for (j = 1; j <= star; j++)
if(i + n <= j + n)
System.out.print(“*”);
System.out.println();
space–;
count = 1;
}
}
}