patternprogram_110 softethics

Pattern 110

C

#include <stdio.h>

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

  int x = 1, y = n;
  int t1,t2;
  int r1,r2;

  for(i = n; i >= 1; i--)
  {
    t1 = x;
    t2 = y;
    r1 = i;
    r2 = i + 1;

    for(s = 1; s<i; s++)
    {
      printf("   "); // 3ws
    }

    for (j = n; j >= i; j--)
    {
      if ((i + j) % 2 == 1)
      {
        printf("%2d ", t1);
      }
      else
      {
        printf("%2d ", t2);
      }
      t1 = t1 - r1++;
      t2 = t2 - r2++;
    }
    y = y + i - 1;
    x = x + i;
    printf("\n");
  }
  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