patternprogram_157 softethics

Pattern 157

C

#include<stdio.h>

int main()
{
  int m=0;

  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",m+65);  // 65 is the ASCII of 'A'
    }
    m+=2;
    printf("\n");
  }
  return 0;
}

C++

 #include<iostream.h>
 
 int main()
 {
 int m=0;
 
 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(m+65);  // 65 is the ASCII of 'A'
 }
 m+=2;
 cout<<endl;
 }
 return 0;
 }

Java

   class PatternProg
   {
     public static void main(String args[])
     {
     int m = 0;
 
     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)(m + 65));
     }
     m += 2;
     System.out.print("\n");
     }
      
     }
 }

C#

using System;

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

    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)(m + 65));
      }
      m += 2;
      Console.WriteLine();
    }
    Console.ReadKey(true);
  }
}

Python

inc = 1
char = 65  # ASCII of 'A'
for x in range(5, 0, -1):
    for y in range(x, 0, -1):
        print(" ", end="")
    print(chr(char) * inc, end="")
    char += 2
    inc += 2;
    print()

Tutorial (YouTube)

5 1 vote
Rate this Program
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments