C
#include <stdio.h>
int main()
{
/* high value => more col. per row */
int n = 7;
int x = n / 2, y = 1;
int i,j;
for(i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
{
if (j <= x || j >= n / 2 + x)
{
printf(" "); // 2ws
}
else
{
printf("%2d", y++);
}
}
printf("\n");
if (i <= n / 2)
x--;
else
x++;
}
return 0;
}
C++
#include <iostream.h>
int main()
{
/* high value => more col. per row */
int n = 7;
int x = n / 2, y = 1;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
if (j <= x || j >= n / 2 + x)
{
cout<<" "; // 2ws
}
else
{
cout<<y++<<" ";
}
}
cout<<endl;
if (i <= n / 2)
x--;
else
x++;
}
return 0;
}
Java
class PatternProg
{
public static void main(String args[])
{
/* high value => more col. per row */
int n = 7;
int x = n / 2;
int y = 1;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if ((j <= x) != false || j >= n / 2 + x)
{
System.out.print(" ");
}
else
{
System.out.print(y+" ");
y++;
}
}
System.out.println();
if (i <= n / 2)
{
x--;
}
else
{
x++;
}
}
}
}
C#
using System;
class PatternProg
{
public static void Main()
{
/* high value => more col. per row */
int n = 7;
int x = n / 2;
int y = 1;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if ((j <= x) != false || j >= n / 2 + x)
{
Console.Write(" ");
}
else
{
Console.Write(y + " ");
y++;
}
}
Console.WriteLine();
if (i <= n / 2)
{
x--;
}
else
{
x++;
}
}
Console.ReadKey(true);
}
}
Python
"""
high value = > more col.per row
"""
n = 7
d = n // 2
e = 1
for x in range(1, n + 1):
for y in range(1, n + 1):
if (y <= d) != 0 or y >= n // 2 + d:
print(" ", end="") # 2ws
else:
print(str(e) + " ", end="")
e += 1
print()
if x <= n // 2:
d -= 1
else:
d += 1