patternprogram_403 softethics

Pattern 403

C

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

int main()
{
  int size=4;
  int i,j,k;
  int p;

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

    /*initialize p with 0 (i>=0) or j */

    p=(i>=0)?0:j;

    for(k=size; k>=abs(i); k--)
    {
      printf("%c ",p+65);
      p++;
    }
    printf("\n");
  }
  return 0;
}

C++

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

 int main()
 {
 int size=4;
 int i,j,k;
 int p;
 
 for(i=size;i>=-size;i--)
 {
  for(j=0;j<abs(i);j++)
  {
   cout<<" ";
  }
 
 /*initialize p with 0 (i>=0) or j */
 
 p=(i>=0)?0:j;

 for(k=size;k>=abs(i);k--)
 {
   cout<<char(p+65)<<" ";
   p++;
 }
  cout<<endl;
 }
  return 0;
 }

Java

class PatternProg
{
    public static void main(String args[])
    {
        int size = 4;
        int p;
        int i,j;

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

            /*initialize p with 0 (i>=0) or j */

            p=(i>=0)?0:j;

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

            System.out.println();
        }
    }
}

C#

using System;

class PatternProg
{
  public static void Main()
  {
    int size = 4;
    int p;
    int i, j, k;

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


      /*initialize p with 0 (i>=0) or j */

      p = (i >= 0) ? 0 : j;

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

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

Python

size = 4
p = 0
for x in range(size, -(size + 1), -1):
    for y in range(1, abs(x) + 1):
        print(" ", end="")

    if (x >= 0):
        p = 0
    else:
        p = y

    for z in range(size, abs(x) - 1, -1):
        print(chr(p + 65) + " ", 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