Pattern 161

Pattern 161 post thumbnail image

C

#include<stdio.h>

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

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

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

C++

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

Java

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

C#

using System;

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

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

      for (int k = i; k >= -i; k--)
      {
        Console.Write((char)(i - Math.Abs(k) + 65));
      }
      z += 2;
      Console.WriteLine();
    }
    Console.ReadKey(true);
  }
}

Python

inc = 1
for x in range(0, 5):
    for y in range(4, x, -1):
        print(" ", end="")
    for z in range(x, -(x + 1), -1):
        print(chr(x - abs(z) + 65), end="")
    print()
0 0 votes
Rate this Program
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Related Patterns