Pattern 409

Pattern 409 post thumbnail image

C

#include <stdio.h>

int main()
{
  int n = 7;
  int i,j,k;
  int x = 1, y = n / 2;
  for(i = 1; i <= n; i++)
  {
    for(j = 1; j <= y; j++)
    {
      printf("  ");
    }
    for(k = x; k >= 1; k--)
    {
      printf("%c ",64 + k);
    }
    printf("\n");

    if (i <= n / 2)
    {
      x += 2;
      y--;
    }
    else
    {
      x -= 2;
      y++;
    }
  }
  return 0;
}

C++

#include <iostream.h>

int main()
{
  int n = 7;
  
  int x = 1, y = n / 2;
  for(int i = 1; i <= n; i++)
  {
    for(int j = 1; j <= y; j++)
    {
      cout<<"  "; // 2ws
    }
    for(int k = x; k >= 1; k--)
    {
      cout<<(char)(64 + k)<<" ";
    }
    cout<<endl;

    if (i <= n / 2)
    {
      x += 2;
      y--;
    }
    else
    {
      x -= 2;
      y++;
    }
  }
  return 0;
}

Java

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

	  int x = 1;
	  int y = n / 2;
	  for (int i = 1; i <= n; i++)
	  {
		for (int j = 1; j <= y; j++)
		{
		  System.out.print("  "); //2ws
		}
		for (int k = x; k >= 1; k--)
		{
		  System.out.print((char)(64 + k)+" ");
		}
		System.out.println();

		if (i <= n / 2)
		{
		  x += 2;
		  y--;
		}
		else
		{
		  x -= 2;
		  y++;
		}
	  }
	  
	}
}

C#

using System;

class PatternProg
{
  public static void Main()
  {
    int n = 7;

    int x = 1;
    int y = n / 2;
    for (int i = 1; i <= n; i++)
    {
      for (int j = 1; j <= y; j++)
      {
        Console.Write("  "); //2ws
      }
      for (int k = x; k >= 1; k--)
      {
        Console.Write((char)(64 + k) + " ");
      }
      Console.WriteLine();

      if (i <= n / 2)
      {
        x += 2;
        y--;
      }
      else
      {
        x -= 2;
        y++;
      }
    }

    Console.ReadKey(true);

  }
}

Python

n = 7
d = 1
e = n // 2

for x in range(1, n + 1):
    for y in range(1, e + 1):
        print("  ", end="")  # 2ws
    for z in range(d, 0, -1):
        print(chr(64 + z) + " ", end="")

    print()

    if x <= n // 2:
        d += 2
        e -= 1
    else:
        d -= 2
        e += 1
0 0 votes
Rate this Program
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Related Patterns