patternprogram_155 softethics

Pattern 155

C

#include <stdio.h>

int main()
{
  int n = 3; // prefer odd
  int i,j,k,z=1;
  int px=1;

  for(i = 1; i <= n; i++)
  {
    for (j = n-1; j >=i; j--)
    {
      printf("   ");// 3ws
    }

    for (k = 0; k <z; k++)
    {
      printf("%2d ",px*px);
      px++;
    }

    z+=2;
    printf("\n");
  }


  return 0;
}

C++

#include <iostream.h>
#include <iomanip.h>

int main()
{
  int n = 3; // prefer odd 
  int z=1;
  int px=1;

  for(int i = 1; i <= n; i++)
  {
    for(int j = n-1; j >=i; j--)
    {
        cout<<setw(3)<<" ";
    }
    
    for (int k = 0; k <z; k++)
    {
        cout<<setw(3)<<px*px;
        px++;
    }
      
      z+=2;
      cout<<endl;
   }
        
  
  return 0;
}

Java

class PatternProg
{
	public static void main(String args[])
	{
	  int n = 3; // prefer odd
	  int z = 1;
	  int px = 1;

	  for (int i = 1; i <= n; i++)
	  {
		for (int j = n - 1; j >= i; j--)
		{
			System.out.print("   "); //3ws
		}

		for (int k = 0; k < z; k++)
		{
			System.out.printf("%3d", px * px);
			px++;
		}

		  z += 2;
		  System.out.println();
	  }


	  
	}
}

C#

using System;

class PatternProg
{
  public static void Main()
  {
    int n = 3; // prefer odd
    int z = 1;
    int px = 1;

    for (int i = 1; i <= n; i++)
    {
      for (int j = n - 1; j >= i; j--)
      {
        Console.Write("   "); //3ws
      }

      for (int k = 0; k < z; k++)
      {
        Console.Write("{0,3:D}", px * px);
        px++;
      }

      z += 2;
      Console.WriteLine();
    }



    Console.ReadKey(true);
  }
}

Python

n = 3  # prefer odd
a = 1
px = 1

for x in range(1, n + 1):
    for y in range(n - 1, x - 1, -1):
        print("   ", end="")  # 3ws
    for z in range(0, a):
        print("{:3d}".format(px * px), end="")
        px += 1
    a += 2
    print()
0 0 votes
Rate this Program
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments