Pattern 441

Pattern 441 post thumbnail image

C

#include <stdio.h>

int main()
{
  /* high value => more col. per row */
  int n = 7;
  int x = n / 2;
  int i,j;

  for(i = 1; i <= n; i++)
  {
    for (j = 1; j <= n; j++)
    {
      if (j <= x || j >= n / 2 + x)
      {
        printf("  "); // 2ws
      }
      else
      {
        printf("%d ", j);
      }
    }
    printf("\n");

    if (i <= n / 2)
      x--;
    else
      x++;
  }
  return 0;
}

C++

#include <iostream.h>

int main()
{
  /* high value => more col. per row */
  int n = 7;
  int x = n / 2;
  

  for(int i = 1; i <= n; i++)
  {
    for(int j = 1; j <= n; j++)
    {
      if (j <= x || j >= n / 2 + x)
      {
        cout<<"  "; // 2ws
      }
      else
      {
        cout<<j<<" ";
      }
    }
    cout<<endl;

    if (i <= n / 2)
      x--;
    else
      x++;
  }
  return 0;
}

Java

class PatternProg
{
	public static void main(String args[])
	{
	  /* high value => more col. per row */
	  int n = 7;
	  int x = n / 2;


	  for (int i = 1; i <= n; i++)
	  {
		for (int j = 1; j <= n; j++)
		{
		  if ((j <= x) != false || j >= n / 2 + x)
		  {
			System.out.print("  "); //2ws
		  }
		  else
		  {
			System.out.print(j+" ");
		  }
		}
		System.out.println();

		if (i <= n / 2)
		{
		  x--;
		}
		else
		{
		  x++;
		}
	  }
	  
	}
}

C#

using System;

class PatternProg
{
  public static void Main()
  {
    /* high value => more col. per row */
    int n = 7;
    int x = n / 2;


    for (int i = 1; i <= n; i++)
    {
      for (int j = 1; j <= n; j++)
      {
        if ((j <= x) != false || j >= n / 2 + x)
        {
          Console.Write("  "); //2ws
        }
        else
        {
          Console.Write(j + " ");
        }
      }
      Console.WriteLine();

      if (i <= n / 2)
      {
        x--;
      }
      else
      {
        x++;
      }
    }


    Console.ReadKey(true);
  }
}

Python

"""
high value = > more col.per row
"""
n = 7
d = n // 2

for x in range(1, n + 1):
  for y in range(1, n + 1):
    if (y <= d) != 0 or y >= n // 2 + d:
        print("  ", end="")  # 2ws
    else:
        print(str(y)+" ", end="")

  print()

  if x <= n // 2:
     d -= 1
  else:
     d += 1
0 0 votes
Rate this Program
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Related Patterns