Pattern 154

Pattern 154 post thumbnail image

C

#include<stdio.h>   // header file


int main()
{
  int i,j,k=1;
  int n=3;//size
  int x=1,z;
  int g;

  for(i=0; i<n; i++)
  {

    for(z=n-1; z>=i; z--)
    {
      printf("  ");
    }

    for(j=0; j<k; j++)
    {
      if(i==j)
      {
        g=(x+1)*(j+j);
        g=(g==0)?1:g;
        printf(" %d",g);
        continue;
      }
      x+=2;
      printf(" %d",x);
    }
    k+=2;
    printf("\n");
  }

}

C++

 #include<iostream.h>
 
 
 int main()
 {
 int i,j,k=1;
 int n=3;//size
 int x=1,z;
 int g;
 
 for(i=0;i<n;i++)
 {
 
 for(z=n-1;z>=i;z--)
 {
   cout<<"  ";
 }
 
 for(j=0;j<k;j++)
 {
  if(i==j)
  {
   g=(x+1)*(j+j);
   g=(g==0)?1:g;
   cout<<" "<<g;
   continue;
  }
   x+=2;
   cout<<" "<<x;
 }
  k+=2;
  cout<<endl;
 }
 
 }

Java

    public class PatternProg
    {
     public static void main(String args[])
     {
     int i;
     int j;
     int k = 1;
     int n = 3; //size
     int x = 1;
     int z;
     int g;
 
     for (i = 0;i < n;i++)
     {
 
     for (z = n - 1;z >= i;z--)
     {
       System.out.print("  ");
     }
 
     for (j = 0;j < k;j++)
     {
      if (i == j)
      {
       g = (x + 1) * (j + j);
       g = (g == 0)?1:g;
       System.out.print(" "+g);
       continue;
      }
       x += 2;
       System.out.print(" "+x);
       }
      k += 2;
      System.out.println();
     }
 
     }
 }

C#

using System;

public class PatternProg
{
  public static void Main()
  {
    int i;
    int j;
    int k = 1;
    int n = 3; //size
    int x = 1;
    int z;
    int g;

    for (i = 0; i < n; i++)
    {

      for (z = n - 1; z >= i; z--)
      {
        Console.Write("  "); // 2 spaces
      }

      for (j = 0; j < k; j++)
      {
        if (i == j)
        {
          g = (x + 1) * (j + j);
          g = (g == 0) ? 1 : g;
          Console.Write(" " + g);
          continue;
        }
        x += 2;

        Console.Write(" " + x);
      }
      k += 2;
      Console.WriteLine();
    }
    Console.ReadKey(true);
  }
}

Python

n = 3  # size
k = 1
p = 1
for x in range(0, n):
    for s in range(n - 1, x, -1):
        print(" ", end="")
    for y in range(0, k):
        if (x == y):
            g = (p + 1) * (y + y)
            if (g == 0):
                g = 1
            print(" " + str(g), end="")
            continue
        p += 2
        print(" " + str(p), end="")
    k += 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