patternprogram_198 softethics

Pattern 198

C

#include <stdio.h>

int main()
{
  int n = 5;// prefer odd
  int i,j;
  int x = 1, y = n * (n * 2) - (n - 1);
  int px,py;

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

    for (j = 1; j <= n; j++)
    {
      if (i <= n / 2 + 1)
      {
        printf("%2d ", px++);
      }
      else
      {
        printf("%2d ", py++);
      }
    }
    printf("\n");
    x = x + (n * 2);
    y = y - (n * 2);
  }
  return 0;
}

C++

Java

C#

Python

0 0 votes
Rate this Program
Subscribe
Notify of
guest


0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments