C
#include<stdio.h>
int main()
{
int n=5; //size
int z=0;
int i,j,k;
for(i=n; i>=1; i--)
{
for(j=1; j<i; j++)
{
printf(" ");
}
for(k=z; k>=0; k--)
{
printf("%2d",k+j);
}
z+=2;
printf("\n");
}
}
/*
Alternate Logic (if-else)
int n = 5;
int i,j;
for(i = 1; i <= n; i++)
{
for (j = 1; j <= n * 2; j++)
{
if (j >= n - i + 1 && j <= n + i - 1)
{
printf("%2d", n * 2 - j);
}
else
{
printf(" ");
}
}
printf("\n");
}
*/
C++
#include<iostream.h>
int main()
{
int n=5; //size
int z=0;
int i,j,k;
for(i = n;i>=1;i--)
{
for(j = 1;j<i;j++)
{
cout<<" "; // 2ws
}
for(k = z;k>=0;k--)
{
cout<<(k + j)<<" ";
}
z+=2;
cout<<endl;
}
}
/*
Alternate Logic (if-else)
int n = 5;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n * 2; j++)
{
if (j >= n - i + 1 && j <= n + i - 1)
{
cout<<(n * 2 - j)<<" ";
}
else
{
cout<<" "; // 2ws
}
}
cout<<endl;
}
*/
Java
class PatternProg
{
public static void main(String args[])
{
int n = 5; //size
int z = 0;
int i;
int j;
int k;
for (i = n;i >= 1;i--)
{
for (j = 1;j < i;j++)
{
System.out.print(" "); //2ws
}
for (k = z;k >= 0;k--)
{
System.out.print((k + j)+" ");
}
z += 2;
System.out.println();
}
}
}
/*
Alternate Logic (if-else)
int n = 5;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n * 2; j++)
{
if (j >= n - i + 1 && j <= n + i - 1)
{
System.out.print((n * 2 - j)+"");
}
else
{
System.out.print(" ");// 2ws
}
}
System.out.println();
}
*/
C#
using System;
class PatternProg
{
public static void Main()
{
int n = 5; //size
int z = 0;
int i;
int j;
int k;
for (i = n; i >= 1; i--)
{
for (j = 1; j < i; j++)
{
Console.Write(" "); //2ws
}
for (k = z; k >= 0; k--)
{
Console.Write((k + j) + " ");
}
z += 2;
Console.WriteLine();
}
Console.ReadKey(true);
}
}
/*
Alternate Logic (if-else)
int n = 5;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n * 2; j++)
{
if (j >= n - i + 1 && j <= n + i - 1)
{
Console.Write((n * 2 - j)+" ");
}
else
{
Console.Write(" ");// 2ws
}
Console.WriteLine();
}
}
*/
Python
n = 5 # size
a = 0
for x in range(n, 0, -1):
for y in range(1, x):
print(" ", end="") # 2ws
for z in range(a, -1, -1):
print(str(z + y)+" ",end="")
a += 2
print()