Pattern 179

Pattern 179 post thumbnail image

C

#include <stdio.h>

int main()
{
  int n = 7;// prefer odd
  int i,j;
  int x = 0;


  for(i = 1; i <= n; i++)
  {
    for(j = 0; j <= x; j++)
    {
      printf("%c", i + 64);
    }
    printf("\n");
    if (i <= n / 2)
      x++;
    else
      x--;
  }
  return 0;
}

C++

#include <iostream.h>

int main()
{
  int n = 7;// prefer odd
   
  int x = 0;
  

  for(int i = 1; i <= n; i++)
  {
    for(int j = 0; j <= x; j++)
    {
      cout<<(char)(i + 64);
    }
    cout<<endl;
    
    if (i <= n / 2)
      x++;
    else
      x--;
  }
  return 0;
}

Java

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

	  int x = 0;


	  for (int i = 1; i <= n; i++)
	  {
		for (int j = 0; j <= x; j++)
		{
		  System.out.print((char)(i + 64));
		}
		System.out.println();

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

C#

using System;

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

    int x = 0;


    for (int i = 1; i <= n; i++)
    {
      for (int j = 0; j <= x; j++)
      {
        Console.Write((char)(i + 64));
      }
      Console.WriteLine();

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

    Console.ReadKey(true);
  }
}

Python

n = 7  # prefer odd
d = 0

for x in range(0, n + 1):
  for y in range(1, d + 1):
    print(chr(x + 64), end="")
  print()

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

Related Patterns