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