patternprogram_112 softethics

Pattern 112

C

#include<stdio.h>


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



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

    printf("\n");
  }
  return 0;
}

C++

#include<iostream.h>


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

  

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

Java

 class PatternProg
 {
   public static void main(String args[])
   {
    int n = 5; // size

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

      System.out.println();
     }
    
   }
}

C#

using System;

class PatternProg
{
  public static void Main()
  {
    int n = 5; // size

    for (int i = 0; i < n; i++)
    {
      for (int j = n - 1; j > i; j--)
      {
        Console.Write(" ");
      }
      for (int k = 0; k <= i; k++)
      {
        Console.Write((char)(k + 65));
      }

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

Python

for x in range(1, 6):
    for y in range(5, x, -1):
        print(" ", end="")
    for z in range(1, x + 1):
        print(chr(z + 64), end="")
    print()

Tutorial (YouTube)

0 0 votes
Rate this Program
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments