patternprogram_440 softethics

Pattern 440

C

#include <stdio.h>

int main()
{
  int n = 4;
  int size = 2 * (n * (n + 1) / 2);
  int x = 1, t;
  int i,j;

  for(i = 1; i <= n; i++)
  {
    t = size - (n - i);

    for(j = 1; j <= 2 * n; j++)
    {
      if (j > 2 * (i - 1))
      {
        if (j <= (2 * n) / 2 + i - 1)
        {
          printf("%02d ", x++);
        }
        else
        {
          printf("%02d ", t++);
        }
      }
      else
      {
        printf("_  "); // '_' with 2 space
      }
    }
    printf("\n");
    size = size - (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