patternprogram_339 softethics

Pattern 339

C

#include<stdio.h>

int main()
{
  int n=6; //size
  int i,j;
  for (i=1; i<=n; i++)
  {
    for (j=1; j<=n; j++)
    {
      if (i%2==0) // for even rows
      {
        if (j%2!=0)
          printf("x");
        else
          printf("o");
      }
      else // for odd rows
      {
        if (j%2!=0)
          printf("o");
        else
          printf("x");
      }
    }
    printf("\n");
  }
  return 0;
}

C++

#include<iostream.h>

int main()
{
    int n=6; //size
    int i,j;
    for (i=1; i<=n; i++)
    {
        for (j=1; j<=n; j++)
        {
            if (i%2==0) // for even rows
            {
                if (j%2!=0)
                    cout<<"x";
                else
                    cout<<"o";
            }
            else // for odd rows
            {
                if (j%2!=0)
                    cout<<"o";
                else
                    cout<<"x";
            }
        }
        cout<<endl;
    }
    return 0;
}

Java

class PatternProg
{
    public static void main(String args[])
    {
        int n = 6; //size
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= n; j++)
            {
                if (i % 2 == 0) // for even rows
                {
                    if (j % 2 != 0)
                    {
                        System.out.print("x");
                    }
                    else
                    {
                        System.out.print("o");
                    }
                }
                else // for odd rows
                {
                    if (j % 2 != 0)
                    {
                        System.out.print("o");
                    }
                    else
                    {
                        System.out.print("x");
                    }
                }
            }
            System.out.println();
        }

    }
}

C#

using System;

class PatternProg
{
  public static void Main()
  {
    int n = 6; //size
    for (int i = 1; i <= n; i++)
    {
      for (int j = 1; j <= n; j++)
      {
        if (i % 2 == 0) // for even rows
        {
          if (j % 2 != 0)
          {
            Console.Write("x");
          }
          else
          {
            Console.Write("o");
          }
        }
        else // for odd rows
        {
          if (j % 2 != 0)
          {
            Console.Write("o");
          }
          else
          {
            Console.Write("x");
          }
        }
      }
      Console.WriteLine();
    }
    Console.ReadKey(true);
  }
}

Python

 n=6
for x in range(1, n+1):
  for y in range(1, n+1):
    if x % 2 == 0: # for even rows
      if y % 2 != 0:
        print("x",end="")
      else:
        print("o",end="")
    else: # for odd rows
      if y % 2 != 0:
        print("o",end="")
      else:
        print("x",end="")
  print()
0 0 votes
Rate this Program
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments