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