Pattern 159

Pattern 159 post thumbnail image

C

#include<stdio.h>

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

  for(i=0; i<n; i++)
  {
    for(j=n-1; j>i; j--)
    {
      printf(" ");
    }
    for(k=0; k<=z; k++)
    {
      printf("%c",z-k+65);
    }
    z+=2;
    printf("\n");
  }
  return 0;
}

C++

 #include<iostream.h>
 
 int main()
 {
 int n=5; //size
 int z=0;
 int i,j,k;
 
 for(i=0;i<n;i++){
 for(j=n-1;j>i;j--)
 {
 cout<<" ";
 }
 for(k=0;k<=z;k++)
 {
 cout<<char(z-k+65);
 }
 z+=2;
 cout<<endl;
 }
 return 0;
 }

Java

   class PatternProg
   {
     public static void main(String args[])
     {
     int n = 5; //size
     int z = 0;
     int i;
     int j;
     int k;
      
     for (i = 0;i < n;i++)
     {
     for (j = n - 1;j > i;j--)
     {
     System.out.print(" ");
     }
     for (k = 0;k <= z;k++)
     {
     System.out.print((char)(z - k + 65));
     }
     z += 2;
     System.out.print("\n");
     }
      
     }
 }

C#

using System;

class PatternProg
{
  public static void Main()
  {
    int n = 5; //size
    int z = 0;
    int i;
    int j;
    int k;

    for (i = 0; i < n; i++)
    {
      for (j = n - 1; j > i; j--)
      {
        Console.Write(" ");
      }
      for (k = 0; k <= z; k++)
      {
        Console.Write((char)(z - k + 65));
      }
      z += 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(inc, 0, -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