Pattern 15

Pattern 15 post thumbnail image

C

#include <stdio.h>

int main()
{
  int n = 5;
  int i,j;
  int x,y;

  for(i = 1; i <= n; i++)
  {
    x = i;
    y = n - i + 1;

    for (j = 1; j <= n; j++)
    {
      if (j % 2 == 0)
      {
        printf("%2d ", x);
      }
      else
      {
        printf("%2d ", y);
      }
      x = x + n;
      y = y + n;
    }
    printf("\n");
  }

  return 0;
}

C++

#include <iostream.h>

int main()
{
  int n = 5;
  
  int x,y;

  for(int i = 1; i <= n; i++)
  {
    x = i;
    y = n - i + 1;

    for(int j = 1; j <= n; j++)
    {
      if (j % 2 == 0)
      {
        cout<<x<<" ";
      }
      else
      {
        cout<<y<<" ";
      }
      x = x + n;
      y = y + n;
    }
    cout<<endl;
  }

  return 0;
}

Java

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

    int x;
    int y;

    for (int i = 1; i <= n; i++)
    {
      x = i;
      y = n - i + 1;

      for (int j = 1; j <= n; j++)
      {
        if (j % 2 == 0)
        {
          System.out.printf("%2d ",x);
        }
        else
        {
          System.out.printf("%2d ",y);
        }
        x = x + n;
        y = y + n;
      }
      System.out.println();
    }


  }
}

C#

using System;

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

    int x;
    int y;

    for (int i = 1; i <= n; i++)
    {
      x = i;
      y = n - i + 1;

      for (int j = 1; j <= n; j++)
      {
        if (j % 2 == 0)
        {
          Console.Write("{0,2:D} ", x);
        }
        else
        {
          Console.Write("{0,2:D} ", y);
        }
        x = x + n;
        y = y + n;
      }
      Console.WriteLine();
    }
    Console.ReadKey(true);

  }
}

Python

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

Related Patterns