Pattern 401

Pattern 401 post thumbnail image

C

#include<stdio.h>

#include<math.h>
int main()
{
  int size=4;
  int i,j,k;
  int p=1;

  for(i=size; i>=-size; i--)
  {
    for(j=1; j<=abs(i); j++)
    {
      printf(" ");
    }

    p=1;
    for(k=size; k>=abs(i); k--)
    {

      printf("%d ",p);

      if(i>=0)
        p++;
      else
        p+=2;

    }



    printf("\n");
  }
  return 0;
}

C++

#include<iostream.h>
#include<math.h>
int main()
{
 int size=3;
 int i,j,k;
 int p=1;

 for(i=size;i>=-size;i--){
 for(j=1;j<=abs(i);j++)
 {
 cout<<" ";
 }
 
 p=1;
 for(k=size;k>=abs(i);k--)
 {
  cout<<p<<" ";
  p++;
 }

 cout<<endl;
 }
return 0;
}

Java

class PatternProg
{
    public static void main(String args[])
    {
        int size = 4;
        int p = 1;// print value

        for (int i = size; i >= -size; i--)
        {
            for (int j = 1; j <= Math.abs(i); j++)
            {
                System.out.print(" ");
            }

            p = 1;
            for (int k = size; k >= Math.abs(i); k--)
            {
                System.out.print(p+" ");
                p++;
            }

            System.out.println();
        }

    }
}

C#

using System;

class PatternProg
{
  public static void Main()
  {
    int size = 4;
    int p = 1; // print value

    for (int i = size; i >= -size; i--)
    {
      for (int j = 1; j <= Math.Abs(i); j++)
      {
        Console.Write(" ");
      }

      p = 1;
      for (int k = size; k >= Math.Abs(i); k--)
      {
        Console.Write(p + " ");
        p++;
      }

      Console.WriteLine();
    }
    Console.ReadKey(true);
  }

}

Python

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

Related Patterns