patternprogram_407 softethics

Pattern 407

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 = 1; k <= x; k++)
    {
      printf("%c ",i + 64);
    }
    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 = 1; k <= x; k++)
    {
      cout<<(char)(i + 64)<<" ";
    }
    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 = 1; k <= x; k++)
		{
		  System.out.print((char)(i + 64)+" ");
		}
		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 = 1; k <= x; k++)
      {
        Console.Write((char)(i + 64) + " ");
      }
      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(x + 64) + " ", 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
Inline Feedbacks
View all comments