Pattern 167

Pattern 167 post thumbnail image

C

#include<stdio.h>

int main()
{
  int p_height=4;
  int width=p_height*2-1;
  int p_space=p_height-1;
  int i,j,k;



  for (i=p_height-1; i>=0; i--)
  {
    for (j=p_space; j>i; j--)
    {
      printf(" ");
    }
    for (k=1; k<=width; k++)
    {
      printf("%c",i+65); //65 -> ASCII of 'A'
    }
    width-=2;
    printf("\n");
  }
  return 0;
}

C++

#include<iostream.h>

int main()
{
    int p_height=4;
    int width=p_height*2-1;
    int p_space=p_height-1;
    int i,j,k;

    

    for (i=p_height-1; i>=0; i--)
    {
        for (j=p_space; j>i; j--)
        {
            cout<<" ";
        }
        for (k=1; k<=width; k++)
        {
            cout<<char(i+65); //65 -> ASCII of 'A'
        }
        width-=2;
        cout<<endl;
    }
    return 0;
}

Java

  class PatternProg
  {
    public static void main(String args[])
    {
        int p_height=4;
        int width=p_height*2-1;
        int p_space=p_height-1;

        for (int i = p_height - 1; i >= 0; i--)
        {
            for (int j = p_space; j >i; j--)
            {
                System.out.print(" ");
            }
            for (int k = 1; k <= width; k++)
            {
                System.out.print((char)(i + 65));
            }
            width -= 2;
            System.out.println();
        }

    }
}

C#

using System;

class PatternProg
{
  public static void Main()
  {
    int p_height = 4;
    int width = p_height * 2 - 1;
    int p_space = p_height - 1;

    for (int i = p_height - 1; i >= 0; i--)
    {
      for (int j = p_space; j > i; j--)
      {
        Console.Write(" ");
      }
      for (int k = 1; k <= width; k++)
      {
        Console.Write((char)(i + 65));
      }
      width -= 2;
      Console.WriteLine();
    }
    Console.ReadKey(true);
  }
}

Python

decr = 7
for x in range(4, 0, -1):
    for y in range(x, 5):
        print(" ", end="")
    for z in range(1, decr + 1):
        print(chr(x + 64), end="")
    decr -= 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