patternprogram_186 softethics

Pattern 186

C

#include <stdio.h>

int main()
{
  int n = 7;
  int x = 1, y = n / 2;
  int i,j,k;

  for(i = 1; i <= n; i++)
  {
    for(j = 1; j <= y; j++)
    {
      printf(" ");
    }
    for(k = 1; k <= x; k++)
    {
      printf("%c", i + 64);
    }
    printf("\n");

    if (i <= n / 2)
    {
      x++;
      y--;
    }
    else
    {
      x--;
      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<<" ";
    }
    for(int k = 1; k <= x; k++)
    {
      cout<<(char)(i + 64);
    }
    cout<<endl;
    
    if (i <= n / 2)
    {
      x++;
      y--;
    }
    else
    {
      x--;
      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(" ");
		}
		for (int k = 1; k <= x; k++)
		{
		  System.out.print((char)(i + 64));
		}
		System.out.println();

		if (i <= n / 2)
		{
		  x++;
		  y--;
		}
		else
		{
		  x--;
		  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(" ");
      }
      for (int k = 1; k <= x; k++)
      {
        Console.Write((char)(i + 64));
      }
      Console.WriteLine();

      if (i <= n / 2)
      {
        x++;
        y--;
      }
      else
      {
        x--;
        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="")

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

  if x <= n // 2:
     d += 1
     e -= 1

  else:
     d -= 1
     e += 1

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