patternprogram_185 softethics

Pattern 185

C

#include<stdio.h>

#include<math.h>
int main()
{
  int size=3;
  int i,j,k;

  for(i=size; i>=-size; i--)
  {
    for(j=1; j<=abs(i); j++)
    {
      printf(" ");
    }

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

C++

 #include<iostream.h>
 
 #include<math.h>
 int main()
 {
 int size=3;
 int i,j,k;
 
 for(i=size;i>=-size;i--){
 for(j=1;j<=abs(i);j++)
 {
 cout<<" ";
 }
 
 for(k=abs(i);k<=size;k++)
 {
 cout<<char(k+65); //65->ASCII of 'A'
 }
 cout<<endl;
 }
 return 0;
 }

Java

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

C#

using System;

class PatternProg
{
  public static void Main()
  {
    int size = 3;

    for (int i = size; i >= -size; i--)
    {
      for (int j = 1; j <= Math.Abs(i); j++)
      {
        Console.Write(" ");
      }

      for (int k = Math.Abs(i); k <= size; k++)
      {
        Console.Write((char)(k + 65));
      }
      Console.WriteLine();
    }
    Console.ReadKey(true);
  }
}

Python

size = 3
for x in range(size, -(size + 1), -1):
    for y in range(abs(x), 0, -1):
        print(" ", end="")
    for z in range(abs(x), 4):
        print(chr(z + 65), end="")
    print()

Tutorial (YouTube)

0 0 votes
Rate this Program
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments