patternprogram_160 softethics

Pattern 160

C

#include<stdio.h>

#include<math.h>
int main()
{
  int n=5;  //size;
  int z=1,l=1;
  int i,j,k;

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

C++

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

Java

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

C#

using System;

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

    for (int i = 0; i < 5; i++)
    {
      for (int j = 4; j > i; j--)
      {
        Console.Write(" ");
      }
      for (int k = 1; k <= z; k++)
      {
        Console.Write((char)(Math.Abs(k - l) + 65));
      }
      l++;
      z += 2;
      Console.WriteLine();
    }
    Console.ReadKey(true);
  }
}

Python

inc = 1
for x in range(1, 6):
    for y in range(5, x, -1):
        print(" ", end="")
    for z in range(1, inc + 1):
        print(chr(abs(z - x) + 65), end="")
    inc += 2;
    print()

Tutorial (YouTube)

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