patternprogram_211 softethics

Pattern 211

C

#include <stdio.h>

int main()
{
  int n = 5;
  int i,j;
  int px,py;

  for(i = 1; i <= n; i++)
  {
    px = i;
    py = n - i + 1;

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

C++

#include <iostream.h>

int main()
{
  int n = 5;
  
  int px,py;

  for(int i = 1; i <= n; i++)
  {
    px = i;
    py = n - i + 1;

    for(int j = 1; j <= n; j++)
    {
      if (j % 2 == 1)
      {
        cout<<(char)(px + 64)<<" ";
      }
      else
      {
        cout<<(char)(py + 64)<<" ";
      }
      px += n;
      py += n;
    }
    cout<<endl;
  }
  return 0;
}

Java

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

	  int px;
	  int py;

	  for (int i = 1; i <= n; i++)
	  {
		px = i;
		py = n - i + 1;

		for (int j = 1; j <= n; j++)
		{
		  if (j % 2 == 1)
		  {
			System.out.print((char)(px + 64)+" ");
		  }
		  else
		  {
			System.out.print((char)(py + 64)+" ");
		  }
		  px += n;
		  py += n;
		}
		System.out.println();
	  }
	  
	}
}

C#

using System;

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

    int px;
    int py;

    for (int i = 1; i <= n; i++)
    {
      px = i;
      py = n - i + 1;

      for (int j = 1; j <= n; j++)
      {
        if (j % 2 == 1)
        {
          Console.Write((char)(px + 64) + " ");
        }
        else
        {
          Console.Write((char)(py + 64) + " ");
        }
        px += n;
        py += n;
      }
      Console.WriteLine();
    }

    Console.ReadKey(true);
  }
}

Python

n = 5

for x in range(1, n + 1):
  px = x
  py = n - x + 1

  for y in range(1, n + 1):
    if y % 2 == 1:
       print(chr(px + 64) + " ", end="")
    else:
       print(chr(py + 64) + " ", end="")

    px += n
    py += n
  print()
0 0 votes
Rate this Program
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments