Pattern 187

Pattern 187 post thumbnail image

C

#include <stdio.h>
#include <math.h>

int main()
{

  int n = 3;
  int i,j,k;

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

C++

#include <iostream.h>
#include <math.h>

int main()
{

 int n = 3;
 

  for(int i = n; i >= -n; i--)
  {
    for(int j = 0; j < abs(i); j++)
    {
      cout<<"  "; // 2ws
    }
    for(int k = 0; k < n-abs(i); k++)
    {
      cout<<(char)(k + 65)<<" ";
    }
    cout<<endl;
  }
 return 0;
}

Java

class PatternProg
{
	public static void main(String args[])
	{

	 int n = 3;


	  for (int i = n; i >= -n; i--)
	  {
		for (int j = 0; j < Math.abs(i); j++)
		{
		  System.out.print("  "); //2ws
		}
		for (int k = 0; k < n - Math.abs(i); k++)
		{
		  System.out.print((char)(k + 65)+" ");
		}
		System.out.println();
	  }
	 
	}
}

C#

using System;

class PatternProg
{
  public static void Main()
  {

    int n = 3;


    for (int i = n; i >= -n; i--)
    {
      for (int j = 0; j < Math.Abs(i); j++)
      {
        Console.Write("  "); //2ws
      }
      for (int k = 0; k < n - Math.Abs(i); k++)
      {
        Console.Write((char)(k + 65) + " ");
      }
      Console.WriteLine();
    }

    Console.ReadKey(true);
  }
}

Python

n = 3

for x in range(n, -(n + 1), -1):
  for y in range(0, abs(x)):
    print(" ", end="")
  for z in range(0, n - abs(x)):
    print(chr(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