Pattern 148

Pattern 148 post thumbnail image

C

#include<stdio.h>
#include<math.h>

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

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

C++

#include<iostream.h>
#include<math.h>

int main()
{
    int n=5; //size
    int z=1;

    for (int i=1; i<=n; i++)
    {
        for (int j=n-1; j>=i; j--)
        {
            cout<<" ";
        }
        for (int k=z; k>=1; k--)
        {
            cout<<abs(k-i);
        }
        z+=2;
        cout<<endl;
    }
}

Java

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

        for (int i=1; i<=n; i++)
        {
            for (int j=n-1; j>=i; j--)
            {
                System.out.print(" ");
            }
            for (int k=z; k>=1; k--)
            {
                System.out.print(Math.abs(k-i));
            }
            z+=2;
            System.out.println();
        }
    } //end of main
}  //end of class

C#

using System;

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

    for (int i = 1; i <= n; i++)
    {
      for (int j = n - 1; j >= i; j--)
      {
        Console.Write(" ");
      }
      for (int k = z; k >= 1; k--)
      {
        Console.Write(Math.Abs(k - i));
      }
      z += 2;
      Console.WriteLine();
    }
    Console.ReadKey(true);
  } //end of main
} //end of class

Python

inc = 1
for x in range(1, 6):
    for y in range(5, x, -1):
        print(" ", end="")
    for z in range(1, inc + 1):
        print(abs(z - x), end="")
    inc += 2;
    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