Pattern 149

Pattern 149 post thumbnail image

C

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

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

    for (k=i-1; k>=-(i-1); k--)
    {
      printf("%d",i-abs(k));
    }
    printf("\n");
  }
  return 0;
}

C++

#include<iostream.h>
#include<math.h>
int main()
{
    for (int i=1; i<=4; i++)
    {
        for (int j=3; j>=i; j--)
        {
            cout<<" ";
        }

        for (int k=i-1; k>=-(i-1); k--)
        {
            cout<<i-abs(k);
        }

        cout<<endl;
    }
    return 0;
}

Java

  class PatternProg
  {
    public static void main(String args[])
    {
        int n=4; //size
        for (int i=1; i<=n; i++)
        {
            for (int j=n-1; j>=i; j--)
            {
                System.out.print(" ");
            }
            for (int k=i-1; k>=-(i-1); k--)
            {
                System.out.print(i-Math.abs(k));
            }
            System.out.println();
        }
    } //end of main
}  //end of class

C#

using System;

class PatternProg
{
  public static void Main()
  {
    int n = 4; //size
    for (int i = 1; i <= n; i++)
    {
      for (int j = n - 1; j >= i; j--)
      {
        Console.Write(" ");
      }
      for (int k = i - 1; k >= -(i - 1); k--)
      {
        Console.Write(i - Math.Abs(k));
      }
      Console.WriteLine();
    }
    Console.ReadKey(true);
  } //end of main
} //end of class

Python

for x in range(1, 5):
    for y in range(4, x, -1):
        print(" ", end="")
    for z in range(x - 1, -x, -1):
        print(x - abs(z), end="")
    print()

Tutorial (YouTube)

0 0 votes
Rate this Program
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Related Patterns