Pattern 158

Pattern 158 post thumbnail image

C

#include<stdio.h>

int main()
{
  int m=1;

  int p_height=5;   //change  value to increase or decrease
  the size of piramid


  int p_space=p_height-1;

  int i,j,k;


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

C++

 #include<iostream.h>
 
 int main()
 {
 int m=1;
 
 int p_height=5;   //change  value to increase or decrease 
              the size of piramid
 
 
 int p_space=p_height-1;
 
 int i,j,k;
 
 
 for(i=0;i<p_height;i++){
 for(j=p_space;j>i;j--)
 {
 cout<<" ";
 }
 for(k=0;k<m;k++)
 {
 cout<<char(k+65);  // 65 is the ASCII of 'A'
 }
 m+=2;
 cout<<endl;
 }
 return 0;
 }

Java

   class PatternProg
   {
     public static void main(String args[])
     {
     int m = 1;
 
     int p_height = 5; //change  value to increase or decrease 
                 the size of piramid
 
 
     int p_space = p_height - 1;
 
     int i;
     int j;
     int k;
 
      
     for (i = 0;i < p_height;i++)
     {
     for (j = p_space;j > i;j--)
     {
     System.out.print(" ");
     }
     for (k = 0;k < m;k++)
     {
     System.out.print((char)(k + 65));
     }
     m += 2;
     System.out.print("\n");
     }
      
     }
 }

C#

using System;

class PatternProg
{
  public static void Main()
  {
    int m = 1;

    int p_height = 5; //change  value to increase or decrease the size of piramid

    int p_space = p_height - 1;

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

Python

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