Pattern 144

Pattern 144 post thumbnail image

C

#include<stdio.h>
int main()
{
  int n=5; //size
  int z=1;
  int i,j,k;

  for(i=n; i>=1; i--)
  {
    for(j=1; j<i; j++)
    {
      printf(" ");
    }
    for(k=1; k<=z; k++)
    {
      printf("%d",i);
    }
    z+=2;
    printf("\n");
  }
}


/*
Alternate Logic (if-else)
int main()
{
 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 - i + 1);
   }
   else
   {
    printf("  "); // 2ws
   }
  }
  printf("\n");
 }
 return 0;
}
*/

C++

 #include<stdio.h>
 int main()
 {
  int n=5; //size
  int z=1;
  
  
  for(int i =n;i>=1;i--)
  {
   for(int j =1;j<i;j++)
   { 
    cout<<"  "; // 2ws //2ws
   }
    for(int k =1;k<=z;k++)
    { 
     cout<<i<<" ";
    }
  z+=2;
  cout<<endl;
  }
 }


/*
Alternate Logic (if-else)
int main()
{
 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 - i + 1)<<" ";
   }
   else
   {
    cout<<"  "; // 2ws
   }
  }
  cout<<endl;
 }
 return 0;
}
*/

Java

  class PatternProg
  {
	 public static void main(String args[])
	 {
	  int n = 5; //size
	  int z = 1;


	  for (int i = n;i >= 1;i--)
	  {
	   for (int j = 1;j < i;j++)
	   {
		System.out.print(" ");
	   }
		for (int k = 1;k <= z;k++)
		{
		 System.out.print(i);
		}
	  z += 2;
	  System.out.println();
	  }
	 }
}
/*
Alternate Logic (if-else)
main()
{
 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)
   {
     Sop((n - i + 1)+" ");
   }
   else
   {
    Sop("  "); // 2ws
   }
  }
 System.out.println();
 }
 
}
*/

C#

using System;

class PatternProg
{
  public static void Main()
  {
    int n = 5; //size
    int z = 1;


    for (int i = n; i >= 1; i--)
    {
      for (int j = 1; j < i; j++)
      {
        Console.Write(" ");
      }
      for (int k = 1; k <= z; k++)
      {
        Console.Write(i);
      }
      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 - i + 1)+" ");
   }
   else
   {
    Console.Write("  "); // 2ws
   }
  }
  cout<<endl;
 }


}
*/

Python

n = 5 # size
a = 1

for x in range(n, 0, -1):
  for y in range(1, x):
    print(" ", end="")
  for z in range(1, a + 1):
    print(x, end="")
  a += 2
  print()
0 0 votes
Rate this Program
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Related Patterns