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