patternprogram_259 softethics

Pattern 259

C

#include <stdio.h>

int main()
{
  int n = 4;
  int total = (n * (n + 1) / 2);
  int px = 1,py;
  int i,j;

  for(i = 1; i <= n; i++)
  {
    py = total - (n - i);
    for (j = 1; j <= n * 2; j++)
    {
      if (j > 2 * (i - 1))
      {
        if (j <= (n * 2) / 2 + i - 1)
        {
          printf("%2d ", px++);
        }
        else
        {
          printf("%2d ", py++);
        }
      }
    }
    printf("\n");
    total = total - (n - i + 1);
  }
  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