Skip to main content

Print the ladder pattern

Here given code implementation process.

//C Program 
//Print the Ladder Pattern
#include <stdio.h>

#include <stdlib.h>

/*Include Space of given size*/
void space(int size)
{
	int counter = 0;
	for (counter = 0; counter < size; counter++)
	{
		//Add space
		printf(" ");
	}
}
void print_symbol(int size)
{
	int counter = 0;
	for (counter = 0; counter < size; counter++)
	{
		printf("━");
	}
}
//Display ladder pattern of given odd size
void print_ladder(int size)
{
	if (size < 0 || size % 2 == 0)
	{
		return;
	}
	printf("\n  Size : %d \n\n", size);
	int i = 0, j = 0;
	for (j = 0; j < size; j++)
	{
		if (j > 0)
		{
			//This condition are used to combine two step ladder pattern
			space(2);
			printf("┃");
			print_symbol(size);
			printf("┃");
			printf("\n");
			j++;
		}
		for (i = 0; i < size; i++)
		{
			//print the bottom layers
			space(2);
			printf("┃");
			if (i == (size / 2))
			{
				print_symbol(size);
			}
			else
			{
				space(size);
			}
			printf("┃");
			printf("\n");
		}
	}
}
int main()
{
	//Test Cases
	print_ladder(3);
	print_ladder(5);
	print_ladder(7);
	return 0;
}

Output

  Size : 3

  ┃   ┃
  ┃━━━┃
  ┃   ┃
  ┃━━━┃
  ┃   ┃
  ┃━━━┃
  ┃   ┃

  Size : 5

  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃

  Size : 7

  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
/*
  Java Program
  Print the ladder pattern
*/
class MyPattern
{
	public void space(int size)
	{
		int counter = 0;
		for (counter = 0; counter < size; counter++)
		{
			//Add space
			System.out.print(" ");
		}
	}
	public void print_symbol(int size)
	{
		int counter = 0;
		for (counter = 0; counter < size; counter++)
		{
			System.out.print("━");
		}
	}
	//Display ladder pattern of given odd size
	public void print_ladder(int size)
	{
		if (size < 0 || size % 2 == 0)
		{
			return;
		}
		System.out.print("\n Size : " + size + " \n\n");
		int i = 0, j = 0;
		for (j = 0; j < size; j++)
		{
			if (j > 0)
			{
				//This condition are used to combine two step ladder pattern
				space(2);
				System.out.print("┃");
				print_symbol(size);
				System.out.print("┃");
				System.out.print("\n");
				j++;
			}
			for (i = 0; i < size; i++)
			{
				//print the bottom layers
				space(2);
				System.out.print("┃");
				if (i == (size / 2))
				{
					print_symbol(size);
				}
				else
				{
					space(size);
				}
				System.out.print("┃");
				System.out.print("\n");
			}
		}
	}
	public static void main(String[] args)
	{
		MyPattern obj = new MyPattern();
		//Test Cases
		obj.print_ladder(3);
		obj.print_ladder(5);
		obj.print_ladder(7);
	}
}

Output

 Size : 3

  ┃   ┃
  ┃━━━┃
  ┃   ┃
  ┃━━━┃
  ┃   ┃
  ┃━━━┃
  ┃   ┃

 Size : 5

  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃

 Size : 7

  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
/*
  C++ Program
  Print the ladder pattern
*/
#include<iostream>

using namespace std;
class MyPattern
{
	public: void space(int size)
	{
		int counter = 0;
		for (counter = 0; counter < size; counter++)
		{
			cout << " ";
		}
	}
	void print_symbol(int size)
	{
		int counter = 0;
		for (counter = 0; counter < size; counter++)
		{
			cout << "━";
		}
	}
	//Display ladder pattern of given odd size
	void print_ladder(int size)
	{
		if (size < 0 || size % 2 == 0)
		{
			return;
		}
		cout << "\n Size : " << size << " \n\n";
		int i = 0, j = 0;
		for (j = 0; j < size; j++)
		{
			if (j > 0)
			{
				//This condition are used to combine two step ladder pattern
				this->space(2);
				cout << "┃";
				this->print_symbol(size);
				cout << "┃";
				cout << "\n";
				j++;
			}
			for (i = 0; i < size; i++)
			{
				//print the bottom layers
				this->space(2);
				cout << "┃";
				if (i == (size / 2))
				{
					this->print_symbol(size);
				}
				else
				{
					this->space(size);
				}
				cout << "┃";
				cout << "\n";
			}
		}
	}
};
int main()
{
	MyPattern obj = MyPattern();
	//Test Cases
	obj.print_ladder(3);
	obj.print_ladder(5);
	obj.print_ladder(7);
	return 0;
}

Output

 Size : 3

  ┃   ┃
  ┃━━━┃
  ┃   ┃
  ┃━━━┃
  ┃   ┃
  ┃━━━┃
  ┃   ┃

 Size : 5

  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃

 Size : 7

  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
/*
  C# Program
  Print the ladder pattern
*/
using System;
class MyPattern
{
	public void space(int size)
	{
		int counter = 0;
		for (counter = 0; counter < size; counter++)
		{
			//Add space
			Console.Write(" ");
		}
	}
	public void print_symbol(int size)
	{
		int counter = 0;
		for (counter = 0; counter < size; counter++)
		{
			Console.Write("━");
		}
	}
	//Display ladder pattern of given odd size
	public void print_ladder(int size)
	{
		if (size < 0 || size % 2 == 0)
		{
			return;
		}
		Console.Write("\n Size : " + size + " \n\n");
		int i = 0, j = 0;
		for (j = 0; j < size; j++)
		{
			if (j > 0)
			{
				//This condition are used to combine two step ladder pattern
				space(2);
				Console.Write("┃");
				print_symbol(size);
				Console.Write("┃");
				Console.Write("\n");
				j++;
			}
			for (i = 0; i < size; i++)
			{
				//print the bottom layers
				space(2);
				Console.Write("┃");
				if (i == (size / 2))
				{
					print_symbol(size);
				}
				else
				{
					space(size);
				}
				Console.Write("┃");
				Console.Write("\n");
			}
		}
	}
	public static void Main(String[] args)
	{
		MyPattern obj = new MyPattern();
		//Test Cases
		obj.print_ladder(3);
		obj.print_ladder(5);
		obj.print_ladder(7);
	}
}

Output

 Size : 3

  ┃   ┃
  ┃━━━┃
  ┃   ┃
  ┃━━━┃
  ┃   ┃
  ┃━━━┃
  ┃   ┃

 Size : 5

  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃

 Size : 7

  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
<?php
/*
  Php Program
  Print the ladder pattern
*/
class MyPattern
{
	public	function space($size)
	{
		$counter = 0;
		for ($counter = 0; $counter < $size; $counter++)
		{
			//Add space
			echo(" ");
		}
	}
	public	function print_symbol($size)
	{
		$counter = 0;
		for ($counter = 0; $counter < $size; $counter++)
		{
			echo("━");
		}
	}
	//Display ladder pattern of given odd size
	public	function print_ladder($size)
	{
		if ($size < 0 || $size % 2 == 0)
		{
			return;
		}
		echo("\n Size : ". $size ." \n\n");
		$i = 0;
		$j = 0;
		for ($j = 0; $j < $size; $j++)
		{
			if ($j > 0)
			{
				//This condition are used to combine two step ladder pattern
				$this->space(2);
				echo("┃");
				$this->print_symbol($size);
				echo("┃");
				echo("\n");
				$j++;
			}
			for ($i = 0; $i < $size; $i++)
			{
				//print the bottom layers
				$this->space(2);
				echo("┃");
				if ($i == (intval($size / 2)))
				{
					$this->print_symbol($size);
				}
				else
				{
					$this->space($size);
				}
				echo("┃");
				echo("\n");
			}
		}
	}
}

function main()
{
	$obj = new MyPattern();
	//Test Cases
	$obj->print_ladder(3);
	$obj->print_ladder(5);
	$obj->print_ladder(7);
}
main();

Output

 Size : 3

  ┃   ┃
  ┃━━━┃
  ┃   ┃
  ┃━━━┃
  ┃   ┃
  ┃━━━┃
  ┃   ┃

 Size : 5

  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃

 Size : 7

  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
/*
  Node Js Program
  Print the ladder pattern
*/
class MyPattern
{
	space(size)
	{
		var counter = 0;
		for (counter = 0; counter < size; counter++)
		{
			//Add space
			process.stdout.write(" ");
		}
	}
	print_symbol(size)
	{
		var counter = 0;
		for (counter = 0; counter < size; counter++)
		{
			process.stdout.write("━");
		}
	}
	//Display ladder pattern of given odd size
	print_ladder(size)
	{
		if (size < 0 || size % 2 == 0)
		{
			return;
		}
		process.stdout.write("\n Size : " + size + " \n\n");
		var i = 0;
		var j = 0;
		for (j = 0; j < size; j++)
		{
			if (j > 0)
			{
				//This condition are used to combine two step ladder pattern
				this.space(2);
				process.stdout.write("┃");
				this.print_symbol(size);
				process.stdout.write("┃");
				process.stdout.write("\n");
				j++;
			}
			for (i = 0; i < size; i++)
			{
				//print the bottom layers
				this.space(2);
				process.stdout.write("┃");
				if (i == (parseInt(size / 2)))
				{
					this.print_symbol(size);
				}
				else
				{
					this.space(size);
				}
				process.stdout.write("┃");
				process.stdout.write("\n");
			}
		}
	}
}

function main(args)
{
	var obj = new MyPattern();
	//Test Cases
	obj.print_ladder(3);
	obj.print_ladder(5);
	obj.print_ladder(7);
}
main();

Output

 Size : 3

  ┃   ┃
  ┃━━━┃
  ┃   ┃
  ┃━━━┃
  ┃   ┃
  ┃━━━┃
  ┃   ┃

 Size : 5

  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃

 Size : 7

  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
# Python 3 Program
# Print the ladder pattern

class MyPattern :
	def space(self, size) :
		counter = 0
		while (counter < size) :
			print(" ", end = "")
			counter += 1
		
	
	def print_symbol(self, size) :
		counter = 0
		while (counter < size) :
			print("━", end = "")
			counter += 1
		
	
	# Display ladder pattern of given odd size
	def print_ladder(self, size) :
		if (size < 0 or size % 2 == 0) :
			return
		
		print("\n Size : ", size ," \n\n", end = "")
		i = 0
		j = 0
		while (j < size) :
			if (j > 0) :
				# This condition are used to combine two step ladder pattern
				self.space(2)
				print("┃", end = "")
				self.print_symbol(size)
				print("┃", end = "")
				print("\n", end = "")
				j += 1
			
			i = 0
			while (i < size) :
				# print the bottom layers
				self.space(2)
				print("┃", end = "")
				if (i == (int(size / 2))) :
					self.print_symbol(size)
				else :
					self.space(size)
				
				print("┃", end = "")
				print("\n", end = "")
				i += 1
			
			j += 1
		
	

def main() :
	obj = MyPattern()
	# Test Cases
	obj.print_ladder(3)
	obj.print_ladder(5)
	obj.print_ladder(7)


if __name__ == "__main__": main()

Output

 Size :  3

  ┃   ┃
  ┃━━━┃
  ┃   ┃
  ┃━━━┃
  ┃   ┃
  ┃━━━┃
  ┃   ┃

 Size :  5

  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃

 Size :  7

  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
# Ruby Program
# Print the ladder pattern

class MyPattern

	def space(size)
	
		counter = 0
		while (counter < size)
		
			print(" ")
			counter += 1
		end
	end
	def print_symbol(size)
	
		counter = 0
		while (counter < size)
		
			print("━")
			counter += 1
		end
	end
	# Display ladder pattern of given odd size
	def print_ladder(size)
	
		if (size < 0 || size % 2 == 0)
		
			return
		end
		print("\n Size : ", size ," \n\n")
		i = 0
		j = 0
		while (j < size)
		
			if (j > 0)
			
				# This condition are used to combine two step ladder pattern
				self.space(2)
				print("┃")
				self.print_symbol(size)
				print("┃")
				print("\n")
				j += 1
			end
			i = 0
			while (i < size)
			
				# print the bottom layers
				self.space(2)
				print("┃")
				if (i == (size / 2))
				
					self.print_symbol(size)
				else
				
					self.space(size)
				end
				print("┃")
				print("\n")
				i += 1
			end
			j += 1
		end
	end
end
def main()

	obj = MyPattern.new()
	# Test Cases
	obj.print_ladder(3)
	obj.print_ladder(5)
	obj.print_ladder(7)
end
main()

Output

 Size : 3 

  ┃   ┃
  ┃━━━┃
  ┃   ┃
  ┃━━━┃
  ┃   ┃
  ┃━━━┃
  ┃   ┃

 Size : 5 

  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃

 Size : 7 

  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
/*
  Scala Program
  Print the ladder pattern
*/
class MyPattern
{
	def space(size: Int): Unit = {
		var counter: Int = 0;
		while (counter < size)
		{
			print(" ");
			counter += 1;
		}
	}
	def print_symbol(size: Int): Unit = {
		var counter: Int = 0;
		while (counter < size)
		{
			print("━");
			counter += 1;
		}
	}
	//Display ladder pattern of given odd size
	def print_ladder(size: Int): Unit = {
		if (size < 0 || size % 2 == 0)
		{
			return;
		}
		print("\n Size : " + size + " \n\n");
		var i: Int = 0;
		var j: Int = 0;
		while (j < size)
		{
			if (j > 0)
			{
				//This condition are used to combine two step ladder pattern
				space(2);
				print("┃");
				print_symbol(size);
				print("┃");
				print("\n");
				j += 1;
			}
			i = 0;
			while (i < size)
			{
				//print the bottom layers
				space(2);
				print("┃");
				if (i == ((size / 2).toInt))
				{
					print_symbol(size);
				}
				else
				{
					space(size);
				}
				print("┃");
				print("\n");
				i += 1;
			}
			j += 1;
		}
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var obj: MyPattern = new MyPattern();
		//Test Cases
		obj.print_ladder(3);
		obj.print_ladder(5);
		obj.print_ladder(7);
	}
}

Output

 Size : 3

  ┃   ┃
  ┃━━━┃
  ┃   ┃
  ┃━━━┃
  ┃   ┃
  ┃━━━┃
  ┃   ┃

 Size : 5

  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃

 Size : 7

  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
/*
  Swift Program
  Print the ladder pattern
*/
class MyPattern
{
	func space(_ size: Int)
	{
		var counter: Int = 0;
		while (counter < size)
		{
			print(" ", terminator: "");
			counter += 1;
		}
	}
	func print_symbol(_ size: Int)
	{
		var counter: Int = 0;
		while (counter < size)
		{
			print("━", terminator: "");
			counter += 1;
		}
	}
	//Display ladder pattern of given odd size
	func print_ladder(_ size: Int)
	{
		if (size < 0 || size % 2 == 0)
		{
			return;
		}
		print("\n Size : ", size ," \n\n", terminator: "");
		var i: Int = 0;
		var j: Int = 0;
		while (j < size)
		{
			if (j > 0)
			{
				//This condition are used to combine two step ladder pattern
				self.space(2);
				print("┃", terminator: "");
				self.print_symbol(size);
				print("┃", terminator: "");
				print("\n", terminator: "");
				j += 1;
			}
			i = 0;
			while (i < size)
			{
				//print the bottom layers
				self.space(2);
				print("┃", terminator: "");
				if (i == (size / 2))
				{
					self.print_symbol(size);
				}
				else
				{
					self.space(size);
				}
				print("┃", terminator: "");
				print("\n", terminator: "");
				i += 1;
			}
			j += 1;
		}
	}
}
func main()
{
	let obj: MyPattern = MyPattern();
	//Test Cases
	obj.print_ladder(3);
	obj.print_ladder(5);
	obj.print_ladder(7);
}
main();

Output

 Size :  3

  ┃   ┃
  ┃━━━┃
  ┃   ┃
  ┃━━━┃
  ┃   ┃
  ┃━━━┃
  ┃   ┃

 Size :  5

  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃
  ┃━━━━━┃
  ┃     ┃
  ┃     ┃

 Size :  7

  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃
  ┃━━━━━━━┃
  ┃       ┃
  ┃       ┃
  ┃       ┃




Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment