Print isosceles trapezoid shape

Here given code implementation process.

//C Program 
//Print isosceles trapezoid shape
#include <stdio.h>

//include space character in given size
void include_space(int size)
{
	for (int i = 0; i < size; ++i)
	{
		//include symbol
		printf(" ");
	}
}
//include star symbol in given size
void include_star(int size)
{
	for (int i = 0; i < size; ++i)
	{
		//include symbol
		printf("* ");
	}
}
//Print isosceles trapezoid star pattern of given size
void isosceles_trapezoid(int size)
{
	printf("\n Size : %d  \n\n", size);
	//Loop controlling variable
	int i = 0;
	//Loop, which is execute row operations
	for (i = 0; i < size; ++i)
	{
		include_space(size - i);
		include_star(size + i);
		printf("\n");
	}
}
int main()
{
	//Simple test
	isosceles_trapezoid(4);
	isosceles_trapezoid(7);
	isosceles_trapezoid(10);
	return 0;
}

Output

 Size : 4

    * * * *
   * * * * *
  * * * * * *
 * * * * * * *

 Size : 7

       * * * * * * *
      * * * * * * * *
     * * * * * * * * *
    * * * * * * * * * *
   * * * * * * * * * * *
  * * * * * * * * * * * *
 * * * * * * * * * * * * *

 Size : 10

          * * * * * * * * * *
         * * * * * * * * * * *
        * * * * * * * * * * * *
       * * * * * * * * * * * * *
      * * * * * * * * * * * * * *
     * * * * * * * * * * * * * * *
    * * * * * * * * * * * * * * * *
   * * * * * * * * * * * * * * * * *
  * * * * * * * * * * * * * * * * * *
 * * * * * * * * * * * * * * * * * * *
// Java program
// Print isosceles trapezoid shape
class MyPattern
{
	//include space character in given size
	public void include_space(int size)
	{
		for (int i = 0; i < size; ++i)
		{
			System.out.print(" ");
		}
	}
	//include star symbol in given size
	public void include_star(int size)
	{
		for (int i = 0; i < size; ++i)
		{
			System.out.print("* ");
		}
	}
	//Print isosceles trapezoid star pattern of given size
	public void isosceles_trapezoid(int size)
	{
		System.out.print("\n Size : " + size + " \n\n");
		//Loop controlling variable
		int i = 0;
		//Loop, which is execute row operations
		for (i = 0; i < size; ++i)
		{
			include_space(size - i);
			include_star(size + i);
			System.out.print("\n");
		}
	}
	public static void main(String[] args)
	{
		MyPattern obj = new MyPattern();
		obj.isosceles_trapezoid(4);
		obj.isosceles_trapezoid(7);
		obj.isosceles_trapezoid(10);
	}
}

Output

 Size : 4

    * * * *
   * * * * *
  * * * * * *
 * * * * * * *

 Size : 7

       * * * * * * *
      * * * * * * * *
     * * * * * * * * *
    * * * * * * * * * *
   * * * * * * * * * * *
  * * * * * * * * * * * *
 * * * * * * * * * * * * *

 Size : 10

          * * * * * * * * * *
         * * * * * * * * * * *
        * * * * * * * * * * * *
       * * * * * * * * * * * * *
      * * * * * * * * * * * * * *
     * * * * * * * * * * * * * * *
    * * * * * * * * * * * * * * * *
   * * * * * * * * * * * * * * * * *
  * * * * * * * * * * * * * * * * * *
 * * * * * * * * * * * * * * * * * * *
//Include header file
#include <iostream>

using namespace std;
// C++ program
// Print isosceles trapezoid shape
class MyPattern
{
	public:
		//include space character in given size
		void include_space(int size)
		{
			for (int i = 0; i < size; ++i)
			{
				cout << " ";
			}
		}
	//include star symbol in given size
	void include_star(int size)
	{
		for (int i = 0; i < size; ++i)
		{
			cout << "* ";
		}
	}
	//Print isosceles trapezoid star pattern of given size
	void isosceles_trapezoid(int size)
	{
		cout << "\n Size : " << size << " \n\n";
		//Loop controlling variable
		int i = 0;
		//Loop, which is execute row operations
		for (i = 0; i < size; ++i)
		{
			this->include_space(size - i);
			this->include_star(size + i);
			cout << "\n";
		}
	}
};
int main()
{
	MyPattern obj = MyPattern();
	obj.isosceles_trapezoid(4);
	obj.isosceles_trapezoid(7);
	obj.isosceles_trapezoid(10);
	return 0;
}

Output

 Size : 4

    * * * *
   * * * * *
  * * * * * *
 * * * * * * *

 Size : 7

       * * * * * * *
      * * * * * * * *
     * * * * * * * * *
    * * * * * * * * * *
   * * * * * * * * * * *
  * * * * * * * * * * * *
 * * * * * * * * * * * * *

 Size : 10

          * * * * * * * * * *
         * * * * * * * * * * *
        * * * * * * * * * * * *
       * * * * * * * * * * * * *
      * * * * * * * * * * * * * *
     * * * * * * * * * * * * * * *
    * * * * * * * * * * * * * * * *
   * * * * * * * * * * * * * * * * *
  * * * * * * * * * * * * * * * * * *
 * * * * * * * * * * * * * * * * * * *
//Include namespace system
using System;
// C# program
// Print isosceles trapezoid shape
class MyPattern
{
	//include space character in given size
	public void include_space(int size)
	{
		for (int i = 0; i < size; ++i)
		{
			Console.Write(" ");
		}
	}
	//include star symbol in given size
	public void include_star(int size)
	{
		for (int i = 0; i < size; ++i)
		{
			Console.Write("* ");
		}
	}
	//Print isosceles trapezoid star pattern of given size
	public void isosceles_trapezoid(int size)
	{
		Console.Write("\n Size : " + size + " \n\n");
		//Loop controlling variable
		int i = 0;
		//Loop, which is execute row operations
		for (i = 0; i < size; ++i)
		{
			include_space(size - i);
			include_star(size + i);
			Console.Write("\n");
		}
	}
	public static void Main(String[] args)
	{
		MyPattern obj = new MyPattern();
		obj.isosceles_trapezoid(4);
		obj.isosceles_trapezoid(7);
		obj.isosceles_trapezoid(10);
	}
}

Output

 Size : 4

    * * * *
   * * * * *
  * * * * * *
 * * * * * * *

 Size : 7

       * * * * * * *
      * * * * * * * *
     * * * * * * * * *
    * * * * * * * * * *
   * * * * * * * * * * *
  * * * * * * * * * * * *
 * * * * * * * * * * * * *

 Size : 10

          * * * * * * * * * *
         * * * * * * * * * * *
        * * * * * * * * * * * *
       * * * * * * * * * * * * *
      * * * * * * * * * * * * * *
     * * * * * * * * * * * * * * *
    * * * * * * * * * * * * * * * *
   * * * * * * * * * * * * * * * * *
  * * * * * * * * * * * * * * * * * *
 * * * * * * * * * * * * * * * * * * *
<?php
// Php program
// Print isosceles trapezoid shape
class MyPattern
{
	//include space character in given size
	public	function include_space($size)
	{
		for ($i = 0; $i < $size; ++$i)
		{
			echo " ";
		}
	}
	//include star symbol in given size
	public	function include_star($size)
	{
		for ($i = 0; $i < $size; ++$i)
		{
			echo "* ";
		}
	}
	//Print isosceles trapezoid star pattern of given size
	public	function isosceles_trapezoid($size)
	{
		echo "\n Size : ". $size ." \n\n";
		//Loop controlling variable
		$i = 0;
		//Loop, which is execute row operations
		for ($i = 0; $i < $size; ++$i)
		{
			$this->include_space($size - $i);
			$this->include_star($size + $i);
			echo "\n";
		}
	}
}

function main()
{
	$obj = new MyPattern();
	$obj->isosceles_trapezoid(4);
	$obj->isosceles_trapezoid(7);
	$obj->isosceles_trapezoid(10);
}
main();

Output

 Size : 4

    * * * *
   * * * * *
  * * * * * *
 * * * * * * *

 Size : 7

       * * * * * * *
      * * * * * * * *
     * * * * * * * * *
    * * * * * * * * * *
   * * * * * * * * * * *
  * * * * * * * * * * * *
 * * * * * * * * * * * * *

 Size : 10

          * * * * * * * * * *
         * * * * * * * * * * *
        * * * * * * * * * * * *
       * * * * * * * * * * * * *
      * * * * * * * * * * * * * *
     * * * * * * * * * * * * * * *
    * * * * * * * * * * * * * * * *
   * * * * * * * * * * * * * * * * *
  * * * * * * * * * * * * * * * * * *
 * * * * * * * * * * * * * * * * * * *
// Node Js program
// Print isosceles trapezoid shape
class MyPattern
{
	//include space character in given size
	include_space(size)
	{
		for (var i = 0; i < size; ++i)
		{
			process.stdout.write(" ");
		}
	}
	//include star symbol in given size
	include_star(size)
	{
		for (var i = 0; i < size; ++i)
		{
			process.stdout.write("* ");
		}
	}
	//Print isosceles trapezoid star pattern of given size
	isosceles_trapezoid(size)
	{
		process.stdout.write("\n Size : " + size + " \n\n");
		//Loop controlling variable
		var i = 0;
		//Loop, which is execute row operations
		for (i = 0; i < size; ++i)
		{
			this.include_space(size - i);
			this.include_star(size + i);
			process.stdout.write("\n");
		}
	}
}

function main()
{
	var obj = new MyPattern();
	obj.isosceles_trapezoid(4);
	obj.isosceles_trapezoid(7);
	obj.isosceles_trapezoid(10);
}
main();

Output

 Size : 4

    * * * *
   * * * * *
  * * * * * *
 * * * * * * *

 Size : 7

       * * * * * * *
      * * * * * * * *
     * * * * * * * * *
    * * * * * * * * * *
   * * * * * * * * * * *
  * * * * * * * * * * * *
 * * * * * * * * * * * * *

 Size : 10

          * * * * * * * * * *
         * * * * * * * * * * *
        * * * * * * * * * * * *
       * * * * * * * * * * * * *
      * * * * * * * * * * * * * *
     * * * * * * * * * * * * * * *
    * * * * * * * * * * * * * * * *
   * * * * * * * * * * * * * * * * *
  * * * * * * * * * * * * * * * * * *
 * * * * * * * * * * * * * * * * * * *
#  Python 3 program
#  Print isosceles trapezoid shape
class MyPattern :
	# include space character in given size
	def include_space(self, size) :
		i = 0
		while (i < size) :
			print(" ", end = "")
			i += 1
		
	
	# include star symbol in given size
	def include_star(self, size) :
		i = 0
		while (i < size) :
			print("* ", end = "")
			i += 1
		
	
	# Print isosceles trapezoid star pattern of given size
	def isosceles_trapezoid(self, size) :
		print("\n Size : ", size ," \n\n", end = "")
		# Loop controlling variable
		i = 0
		# Loop, which is execute row operations
		i = 0
		while (i < size) :
			self.include_space(size - i)
			self.include_star(size + i)
			print("\n", end = "")
			i += 1
		
	

def main() :
	obj = MyPattern()
	obj.isosceles_trapezoid(4)
	obj.isosceles_trapezoid(7)
	obj.isosceles_trapezoid(10)

if __name__ == "__main__": main()

Output

 Size :  4

    * * * *
   * * * * *
  * * * * * *
 * * * * * * *

 Size :  7

       * * * * * * *
      * * * * * * * *
     * * * * * * * * *
    * * * * * * * * * *
   * * * * * * * * * * *
  * * * * * * * * * * * *
 * * * * * * * * * * * * *

 Size :  10

          * * * * * * * * * *
         * * * * * * * * * * *
        * * * * * * * * * * * *
       * * * * * * * * * * * * *
      * * * * * * * * * * * * * *
     * * * * * * * * * * * * * * *
    * * * * * * * * * * * * * * * *
   * * * * * * * * * * * * * * * * *
  * * * * * * * * * * * * * * * * * *
 * * * * * * * * * * * * * * * * * * *
#  Ruby program
#  Print isosceles trapezoid shape
class MyPattern

	# include space character in given size
	def include_space(size)
	
		i = 0
		while (i < size)
		
			print(" ")
			i += 1
		end
	end
	# include star symbol in given size
	def include_star(size)
	
		i = 0
		while (i < size)
		
			print("* ")
			i += 1
		end
	end
	# Print isosceles trapezoid star pattern of given size
	def isosceles_trapezoid(size)
	
		print("\n Size : ", size ," \n\n")
		# Loop controlling variable
		i = 0
		# Loop, which is execute row operations
		i = 0
		while (i < size)
		
			self.include_space(size - i)
			self.include_star(size + i)
			print("\n")
			i += 1
		end
	end
end
def main()

	obj = MyPattern.new()
	obj.isosceles_trapezoid(4)
	obj.isosceles_trapezoid(7)
	obj.isosceles_trapezoid(10)
end
main()

Output

 Size : 4 

    * * * * 
   * * * * * 
  * * * * * * 
 * * * * * * * 

 Size : 7 

       * * * * * * * 
      * * * * * * * * 
     * * * * * * * * * 
    * * * * * * * * * * 
   * * * * * * * * * * * 
  * * * * * * * * * * * * 
 * * * * * * * * * * * * * 

 Size : 10 

          * * * * * * * * * * 
         * * * * * * * * * * * 
        * * * * * * * * * * * * 
       * * * * * * * * * * * * * 
      * * * * * * * * * * * * * * 
     * * * * * * * * * * * * * * * 
    * * * * * * * * * * * * * * * * 
   * * * * * * * * * * * * * * * * * 
  * * * * * * * * * * * * * * * * * * 
 * * * * * * * * * * * * * * * * * * * 
// Scala program
// Print isosceles trapezoid shape
class MyPattern
{
	//include space character in given size
	def include_space(size: Int): Unit = {
		var i: Int = 0;
		while (i < size)
		{
			print(" ");
			i += 1;
		}
	}
	//include star symbol in given size
	def include_star(size: Int): Unit = {
		var i: Int = 0;
		while (i < size)
		{
			print("* ");
			i += 1;
		}
	}
	//Print isosceles trapezoid star pattern of given size
	def isosceles_trapezoid(size: Int): Unit = {
		print("\n Size : " + size + " \n\n");
		//Loop controlling variable
		var i: Int = 0;
		//Loop, which is execute row operations
		i = 0;
		while (i < size)
		{
			include_space(size - i);
			include_star(size + i);
			print("\n");
			i += 1;
		}
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var obj: MyPattern = new MyPattern();
		obj.isosceles_trapezoid(4);
		obj.isosceles_trapezoid(7);
		obj.isosceles_trapezoid(10);
	}
}

Output

 Size : 4

    * * * *
   * * * * *
  * * * * * *
 * * * * * * *

 Size : 7

       * * * * * * *
      * * * * * * * *
     * * * * * * * * *
    * * * * * * * * * *
   * * * * * * * * * * *
  * * * * * * * * * * * *
 * * * * * * * * * * * * *

 Size : 10

          * * * * * * * * * *
         * * * * * * * * * * *
        * * * * * * * * * * * *
       * * * * * * * * * * * * *
      * * * * * * * * * * * * * *
     * * * * * * * * * * * * * * *
    * * * * * * * * * * * * * * * *
   * * * * * * * * * * * * * * * * *
  * * * * * * * * * * * * * * * * * *
 * * * * * * * * * * * * * * * * * * *
// Swift program
// Print isosceles trapezoid shape
class MyPattern
{
	//include space character in given size
	func include_space(_ size: Int)
	{
		var i: Int = 0;
		while (i < size)
		{
			print(" ", terminator: "");
			i += 1;
		}
	}
	//include star symbol in given size
	func include_star(_ size: Int)
	{
		var i: Int = 0;
		while (i < size)
		{
			print("* ", terminator: "");
			i += 1;
		}
	}
	//Print isosceles trapezoid star pattern of given size
	func isosceles_trapezoid(_ size: Int)
	{
		print("\n Size : ", size ," \n\n", terminator: "");
		//Loop controlling variable
		var i: Int = 0;
		//Loop, which is execute row operations
		i = 0;
		while (i < size)
		{
			self.include_space(size - i);
			self.include_star(size + i);
			print("\n", terminator: "");
			i += 1;
		}
	}
}
func main()
{
	let obj: MyPattern = MyPattern();
	obj.isosceles_trapezoid(4);
	obj.isosceles_trapezoid(7);
	obj.isosceles_trapezoid(10);
}
main();

Output

 Size :  4

    * * * *
   * * * * *
  * * * * * *
 * * * * * * *

 Size :  7

       * * * * * * *
      * * * * * * * *
     * * * * * * * * *
    * * * * * * * * * *
   * * * * * * * * * * *
  * * * * * * * * * * * *
 * * * * * * * * * * * * *

 Size :  10

          * * * * * * * * * *
         * * * * * * * * * * *
        * * * * * * * * * * * *
       * * * * * * * * * * * * *
      * * * * * * * * * * * * * *
     * * * * * * * * * * * * * * *
    * * * * * * * * * * * * * * * *
   * * * * * * * * * * * * * * * * *
  * * * * * * * * * * * * * * * * * *
 * * * * * * * * * * * * * * * * * * *


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







© 2021, kalkicode.com, All rights reserved