Display Butterfly Pattern

Butterfly Pattern

Here given code implementation process.

//C Program 
//Display Butterfly 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(" ");
  }
}
/*Include Symbol*/
void print_symbol(int size) {

  int counter = 0;

  for (counter = 0; counter < size; counter++) {
    if (counter == 0 || counter + 1 == size) {
      printf("⌖");
    } else {
      printf("⁖");
    }

  }
}


void butterfly_pattern(int size) {


  printf("\n Size : %d \n", size);

  int i = 0;
  //Display the result of top half shell
  for (i = 0; i < size; i++) {
    space(i);
    print_symbol(i);
    space((size *4) - (i *4));
    print_symbol(i);
    printf("\n");
  }
  //Display the result of bottom half shell
  for (i = 0; i < size; i++) {

    space(size - i);
    print_symbol(size - i);
    space((i *4));
    print_symbol(size - i);
    printf("\n");

  }
}


int main() {
  //Test Cases
  butterfly_pattern(4);
  butterfly_pattern(5);
  butterfly_pattern(7);
  return 0;
}

Output

 Size : 4

 ⌖            ⌖
  ⌖⌖        ⌖⌖
   ⌖⁖⌖    ⌖⁖⌖
    ⌖⁖⁖⌖⌖⁖⁖⌖
   ⌖⁖⌖    ⌖⁖⌖
  ⌖⌖        ⌖⌖
 ⌖            ⌖

 Size : 5

 ⌖                ⌖
  ⌖⌖            ⌖⌖
   ⌖⁖⌖        ⌖⁖⌖
    ⌖⁖⁖⌖    ⌖⁖⁖⌖
     ⌖⁖⁖⁖⌖⌖⁖⁖⁖⌖
    ⌖⁖⁖⌖    ⌖⁖⁖⌖
   ⌖⁖⌖        ⌖⁖⌖
  ⌖⌖            ⌖⌖
 ⌖                ⌖

 Size : 7

 ⌖                        ⌖
  ⌖⌖                    ⌖⌖
   ⌖⁖⌖                ⌖⁖⌖
    ⌖⁖⁖⌖            ⌖⁖⁖⌖
     ⌖⁖⁖⁖⌖        ⌖⁖⁖⁖⌖
      ⌖⁖⁖⁖⁖⌖    ⌖⁖⁖⁖⁖⌖
       ⌖⁖⁖⁖⁖⁖⌖⌖⁖⁖⁖⁖⁖⌖
      ⌖⁖⁖⁖⁖⌖    ⌖⁖⁖⁖⁖⌖
     ⌖⁖⁖⁖⌖        ⌖⁖⁖⁖⌖
    ⌖⁖⁖⌖            ⌖⁖⁖⌖
   ⌖⁖⌖                ⌖⁖⌖
  ⌖⌖                    ⌖⌖
 ⌖                        ⌖
/*
  C++ Program
  Display Butterfly Pattern
*/
#include<iostream>

using namespace std;
class MyPattern {
	public:

    /*Include Space of given size*/
    void space(int size) {
      int counter = 0;
      for (counter = 0; counter < size; counter++) {
        //Add space

        cout << " ";
      }
    }
	/*Include Symbol*/
	void print_symbol(int size) {
		int counter = 0;
		for (counter = 0; counter < size; counter++) {
			if (counter == 0 ||
				counter + 1 == size) {
				cout << "⌖";
			} else {
				cout << "⁖";
			}
		}
	}
	void butterfly_pattern(int size) {
		cout << "\n Size : " << size << " \n";
		int i = 0;
		//Display the result of top half shell

		for (i = 0; i < size; i++) {
			this->space(i);
			this->print_symbol(i);
			this->space((size *4) - (i *4));
			this->print_symbol(i);
			cout << "\n";
		}
		//Display the result of bottom half shell

		for (i = 0; i < size; i++) {
			this->space(size - i);
			this->print_symbol(size - i);
			this->space((i *4));
			this->print_symbol(size - i);
			cout << "\n";
		}
	}
};
int main() {
	MyPattern obj =  MyPattern();
	obj.butterfly_pattern(4);
	obj.butterfly_pattern(5);
	obj.butterfly_pattern(7);
	return 0;
}

Output

 Size : 4

 ⌖            ⌖
  ⌖⌖        ⌖⌖
   ⌖⁖⌖    ⌖⁖⌖
    ⌖⁖⁖⌖⌖⁖⁖⌖
   ⌖⁖⌖    ⌖⁖⌖
  ⌖⌖        ⌖⌖
 ⌖            ⌖

 Size : 5

 ⌖                ⌖
  ⌖⌖            ⌖⌖
   ⌖⁖⌖        ⌖⁖⌖
    ⌖⁖⁖⌖    ⌖⁖⁖⌖
     ⌖⁖⁖⁖⌖⌖⁖⁖⁖⌖
    ⌖⁖⁖⌖    ⌖⁖⁖⌖
   ⌖⁖⌖        ⌖⁖⌖
  ⌖⌖            ⌖⌖
 ⌖                ⌖

 Size : 7

 ⌖                        ⌖
  ⌖⌖                    ⌖⌖
   ⌖⁖⌖                ⌖⁖⌖
    ⌖⁖⁖⌖            ⌖⁖⁖⌖
     ⌖⁖⁖⁖⌖        ⌖⁖⁖⁖⌖
      ⌖⁖⁖⁖⁖⌖    ⌖⁖⁖⁖⁖⌖
       ⌖⁖⁖⁖⁖⁖⌖⌖⁖⁖⁖⁖⁖⌖
      ⌖⁖⁖⁖⁖⌖    ⌖⁖⁖⁖⁖⌖
     ⌖⁖⁖⁖⌖        ⌖⁖⁖⁖⌖
    ⌖⁖⁖⌖            ⌖⁖⁖⌖
   ⌖⁖⌖                ⌖⁖⌖
  ⌖⌖                    ⌖⌖
 ⌖                        ⌖
/*
  Java Program
  Display Butterfly Pattern
*/

public class MyPattern {


  /*Include Space of given size*/
  public void space(int size) {

    int counter = 0;

    for (counter = 0; counter < size; counter++) {

      //Add space
      System.out.print(" ");
    }
  }
  /*Include Symbol*/
  public void print_symbol(int size) {

    int counter = 0;

    for (counter = 0; counter < size; counter++) {
      if (counter == 0 || counter + 1 == size) {

        System.out.print("⌖");

      } else {
        System.out.print("⁖");
      }

    }
  }


  public void butterfly_pattern(int size) {


    System.out.print("\n Size : " + size + " \n" );

    int i = 0;

    //Display the result of top half shell
    for (i = 0; i < size; i++) {
      space(i);
      print_symbol(i);
      space((size *4) - (i *4));
      print_symbol(i);
      System.out.print("\n");
    }
    //Display the result of bottom half shell
    for (i = 0; i < size; i++) {

      space(size - i);
      print_symbol(size - i);
      space((i *4));
      print_symbol(size - i);
      System.out.print("\n");

    }
  }
  public static void main(String[] args) {

    MyPattern obj = new MyPattern();
    obj.butterfly_pattern(4);
    obj.butterfly_pattern(5);
    obj.butterfly_pattern(7);

  }
}

Output

 Size : 4

 ⌖            ⌖
  ⌖⌖        ⌖⌖
   ⌖⁖⌖    ⌖⁖⌖
    ⌖⁖⁖⌖⌖⁖⁖⌖
   ⌖⁖⌖    ⌖⁖⌖
  ⌖⌖        ⌖⌖
 ⌖            ⌖

 Size : 5

 ⌖                ⌖
  ⌖⌖            ⌖⌖
   ⌖⁖⌖        ⌖⁖⌖
    ⌖⁖⁖⌖    ⌖⁖⁖⌖
     ⌖⁖⁖⁖⌖⌖⁖⁖⁖⌖
    ⌖⁖⁖⌖    ⌖⁖⁖⌖
   ⌖⁖⌖        ⌖⁖⌖
  ⌖⌖            ⌖⌖
 ⌖                ⌖

 Size : 7

 ⌖                        ⌖
  ⌖⌖                    ⌖⌖
   ⌖⁖⌖                ⌖⁖⌖
    ⌖⁖⁖⌖            ⌖⁖⁖⌖
     ⌖⁖⁖⁖⌖        ⌖⁖⁖⁖⌖
      ⌖⁖⁖⁖⁖⌖    ⌖⁖⁖⁖⁖⌖
       ⌖⁖⁖⁖⁖⁖⌖⌖⁖⁖⁖⁖⁖⌖
      ⌖⁖⁖⁖⁖⌖    ⌖⁖⁖⁖⁖⌖
     ⌖⁖⁖⁖⌖        ⌖⁖⁖⁖⌖
    ⌖⁖⁖⌖            ⌖⁖⁖⌖
   ⌖⁖⌖                ⌖⁖⌖
  ⌖⌖                    ⌖⌖
 ⌖                        ⌖
/*
  C# Program
  Display Butterfly Pattern
*/
using System;

public class MyPattern {
	/*Include Space of given size*/
	public void space(int size) {
		int counter = 0;
		for (counter = 0; counter < size; counter++) {
			Console.Write(" ");
		}
	}
	/*Include Symbol*/
	public void print_symbol(int size) {
		int counter = 0;
		for (counter = 0; counter < size; counter++) {
			if (counter == 0 ||
				counter + 1 == size) {
				Console.Write("⌖");
			} else {
				Console.Write("⁖");
			}
		}
	}
	public void butterfly_pattern(int size) {
		Console.Write("\n Size : " + size + " \n");
		int i = 0;
		//Display the result of top half shell

		for (i = 0; i < size; i++) {
			space(i);
			print_symbol(i);
			space((size * 4) - (i * 4));
			print_symbol(i);
			Console.Write("\n");
		}
		//Display the result of bottom half shell

		for (i = 0; i < size; i++) {
			space(size - i);
			print_symbol(size - i);
			space((i * 4));
			print_symbol(size - i);
			Console.Write("\n");
		}
	}
	public static void Main(String[] args) {
		MyPattern obj = new MyPattern();
		obj.butterfly_pattern(4);
		obj.butterfly_pattern(5);
		obj.butterfly_pattern(7);
	}
}

Output

 Size : 4

 ⌖            ⌖
  ⌖⌖        ⌖⌖
   ⌖⁖⌖    ⌖⁖⌖
    ⌖⁖⁖⌖⌖⁖⁖⌖
   ⌖⁖⌖    ⌖⁖⌖
  ⌖⌖        ⌖⌖
 ⌖            ⌖

 Size : 5

 ⌖                ⌖
  ⌖⌖            ⌖⌖
   ⌖⁖⌖        ⌖⁖⌖
    ⌖⁖⁖⌖    ⌖⁖⁖⌖
     ⌖⁖⁖⁖⌖⌖⁖⁖⁖⌖
    ⌖⁖⁖⌖    ⌖⁖⁖⌖
   ⌖⁖⌖        ⌖⁖⌖
  ⌖⌖            ⌖⌖
 ⌖                ⌖

 Size : 7

 ⌖                        ⌖
  ⌖⌖                    ⌖⌖
   ⌖⁖⌖                ⌖⁖⌖
    ⌖⁖⁖⌖            ⌖⁖⁖⌖
     ⌖⁖⁖⁖⌖        ⌖⁖⁖⁖⌖
      ⌖⁖⁖⁖⁖⌖    ⌖⁖⁖⁖⁖⌖
       ⌖⁖⁖⁖⁖⁖⌖⌖⁖⁖⁖⁖⁖⌖
      ⌖⁖⁖⁖⁖⌖    ⌖⁖⁖⁖⁖⌖
     ⌖⁖⁖⁖⌖        ⌖⁖⁖⁖⌖
    ⌖⁖⁖⌖            ⌖⁖⁖⌖
   ⌖⁖⌖                ⌖⁖⌖
  ⌖⌖                    ⌖⌖
 ⌖                        ⌖
<?php
/*
  Php Program
  Display Butterfly Pattern
*/
class MyPattern {
	/*Include Space of given size*/

	public 	function space($size) {
		$counter = 0;
		for ($counter = 0; $counter < $size; $counter++) {
			//Add space

			echo(" ");
		}
	}
	/*Include Symbol*/

	public 	function print_symbol($size) {
		$counter = 0;
		for ($counter = 0; $counter < $size; $counter++) {
			if ($counter == 0 ||
				$counter + 1 == $size) {
				echo("⌖");
			} else {
				echo("⁖");
			}
		}
	}
	public 	function butterfly_pattern($size) {
		echo("\n Size : ". $size ." \n");
		$i = 0;
		//Display the result of top half shell

		for ($i = 0; $i < $size; $i++) {
			$this->space($i);
			$this->print_symbol($i);
			$this->space(($size *4) - ($i *4));
			$this->print_symbol($i);
			echo("\n");
		}
		//Display the result of bottom half shell

		for ($i = 0; $i < $size; $i++) {
			$this->space($size - $i);
			$this->print_symbol($size - $i);
			$this->space(($i *4));
			$this->print_symbol($size - $i);
			echo("\n");
		}
	}
}

function main() {
	$obj = new MyPattern();
	$obj->butterfly_pattern(4);
	$obj->butterfly_pattern(5);
	$obj->butterfly_pattern(7);

}
main();

Output

 Size : 4

 ⌖            ⌖
  ⌖⌖        ⌖⌖
   ⌖⁖⌖    ⌖⁖⌖
    ⌖⁖⁖⌖⌖⁖⁖⌖
   ⌖⁖⌖    ⌖⁖⌖
  ⌖⌖        ⌖⌖
 ⌖            ⌖

 Size : 5

 ⌖                ⌖
  ⌖⌖            ⌖⌖
   ⌖⁖⌖        ⌖⁖⌖
    ⌖⁖⁖⌖    ⌖⁖⁖⌖
     ⌖⁖⁖⁖⌖⌖⁖⁖⁖⌖
    ⌖⁖⁖⌖    ⌖⁖⁖⌖
   ⌖⁖⌖        ⌖⁖⌖
  ⌖⌖            ⌖⌖
 ⌖                ⌖

 Size : 7

 ⌖                        ⌖
  ⌖⌖                    ⌖⌖
   ⌖⁖⌖                ⌖⁖⌖
    ⌖⁖⁖⌖            ⌖⁖⁖⌖
     ⌖⁖⁖⁖⌖        ⌖⁖⁖⁖⌖
      ⌖⁖⁖⁖⁖⌖    ⌖⁖⁖⁖⁖⌖
       ⌖⁖⁖⁖⁖⁖⌖⌖⁖⁖⁖⁖⁖⌖
      ⌖⁖⁖⁖⁖⌖    ⌖⁖⁖⁖⁖⌖
     ⌖⁖⁖⁖⌖        ⌖⁖⁖⁖⌖
    ⌖⁖⁖⌖            ⌖⁖⁖⌖
   ⌖⁖⌖                ⌖⁖⌖
  ⌖⌖                    ⌖⌖
 ⌖                        ⌖
/*
  Node Js Program
  Display Butterfly Pattern
*/
class MyPattern {
	/*Include Space of given size*/
	space(size) {
		var counter = 0;
		for (counter = 0; counter < size; counter++) {
			//Add space

			process.stdout.write(" ");
		}
	}

	/*Include Symbol*/
	print_symbol(size) {
		var counter = 0;
		for (counter = 0; counter < size; counter++) {
			if (counter == 0 ||
				counter + 1 == size) {
				process.stdout.write("⌖");
			} else {
				process.stdout.write("⁖");
			}
		}
	}
	butterfly_pattern(size) {
		process.stdout.write("\n Size : " + size + " \n");
		var i = 0;
		//Display the result of top half shell

		for (i = 0; i < size; i++) {
			this.space(i);
			this.print_symbol(i);
			this.space((size *4) - (i *4));
			this.print_symbol(i);
			process.stdout.write("\n");
		}

		//Display the result of bottom half shell

		for (i = 0; i < size; i++) {
			this.space(size - i);
			this.print_symbol(size - i);
			this.space((i *4));
			this.print_symbol(size - i);
			process.stdout.write("\n");
		}
	}
}

function main(args) {
	var obj = new MyPattern();
	obj.butterfly_pattern(4);
	obj.butterfly_pattern(5);
	obj.butterfly_pattern(7);
}

main();

Output

 Size : 4

 ⌖            ⌖
  ⌖⌖        ⌖⌖
   ⌖⁖⌖    ⌖⁖⌖
    ⌖⁖⁖⌖⌖⁖⁖⌖
   ⌖⁖⌖    ⌖⁖⌖
  ⌖⌖        ⌖⌖
 ⌖            ⌖

 Size : 5

 ⌖                ⌖
  ⌖⌖            ⌖⌖
   ⌖⁖⌖        ⌖⁖⌖
    ⌖⁖⁖⌖    ⌖⁖⁖⌖
     ⌖⁖⁖⁖⌖⌖⁖⁖⁖⌖
    ⌖⁖⁖⌖    ⌖⁖⁖⌖
   ⌖⁖⌖        ⌖⁖⌖
  ⌖⌖            ⌖⌖
 ⌖                ⌖

 Size : 7

 ⌖                        ⌖
  ⌖⌖                    ⌖⌖
   ⌖⁖⌖                ⌖⁖⌖
    ⌖⁖⁖⌖            ⌖⁖⁖⌖
     ⌖⁖⁖⁖⌖        ⌖⁖⁖⁖⌖
      ⌖⁖⁖⁖⁖⌖    ⌖⁖⁖⁖⁖⌖
       ⌖⁖⁖⁖⁖⁖⌖⌖⁖⁖⁖⁖⁖⌖
      ⌖⁖⁖⁖⁖⌖    ⌖⁖⁖⁖⁖⌖
     ⌖⁖⁖⁖⌖        ⌖⁖⁖⁖⌖
    ⌖⁖⁖⌖            ⌖⁖⁖⌖
   ⌖⁖⌖                ⌖⁖⌖
  ⌖⌖                    ⌖⌖
 ⌖                        ⌖
#   Python 3 Program
#   Display Butterfly Pattern

class MyPattern :
	# Include Space of given size
	def space(self, size) :
		counter = 0
		while (counter < size) :
			print(" ", end = "")
			counter += 1
		
	
	# Include Symbol
	def print_symbol(self, size) :
		counter = 0
		while (counter < size) :
			if (counter == 0 or counter + 1 == size) :
				print("⌖", end = "")
			else :
				print("⁖", end = "")
			
			counter += 1
		
	
	def butterfly_pattern(self, size) :
		print("\n Size : ", size ," \n", end = "")
		i = 0
		# Display the result of top half shell
		while (i < size) :
			self.space(i)
			self.print_symbol(i)
			self.space((size * 4) - (i * 4))
			self.print_symbol(i)
			print("\n", end = "")
			i += 1
		
		i = 0
		# Display the result of bottom half shell
		while (i < size) :
			self.space(size - i)
			self.print_symbol(size - i)
			self.space((i * 4))
			self.print_symbol(size - i)
			print("\n", end = "")
			i += 1
		
	

def main() :
	obj = MyPattern()
	obj.butterfly_pattern(4)
	obj.butterfly_pattern(5)
	obj.butterfly_pattern(7)


if __name__ == "__main__":
	main()

Output

 Size :  4

 ⌖            ⌖
  ⌖⌖        ⌖⌖
   ⌖⁖⌖    ⌖⁖⌖
    ⌖⁖⁖⌖⌖⁖⁖⌖
   ⌖⁖⌖    ⌖⁖⌖
  ⌖⌖        ⌖⌖
 ⌖            ⌖

 Size :  5

 ⌖                ⌖
  ⌖⌖            ⌖⌖
   ⌖⁖⌖        ⌖⁖⌖
    ⌖⁖⁖⌖    ⌖⁖⁖⌖
     ⌖⁖⁖⁖⌖⌖⁖⁖⁖⌖
    ⌖⁖⁖⌖    ⌖⁖⁖⌖
   ⌖⁖⌖        ⌖⁖⌖
  ⌖⌖            ⌖⌖
 ⌖                ⌖

 Size :  7

 ⌖                        ⌖
  ⌖⌖                    ⌖⌖
   ⌖⁖⌖                ⌖⁖⌖
    ⌖⁖⁖⌖            ⌖⁖⁖⌖
     ⌖⁖⁖⁖⌖        ⌖⁖⁖⁖⌖
      ⌖⁖⁖⁖⁖⌖    ⌖⁖⁖⁖⁖⌖
       ⌖⁖⁖⁖⁖⁖⌖⌖⁖⁖⁖⁖⁖⌖
      ⌖⁖⁖⁖⁖⌖    ⌖⁖⁖⁖⁖⌖
     ⌖⁖⁖⁖⌖        ⌖⁖⁖⁖⌖
    ⌖⁖⁖⌖            ⌖⁖⁖⌖
   ⌖⁖⌖                ⌖⁖⌖
  ⌖⌖                    ⌖⌖
 ⌖                        ⌖
#   Ruby Program
#   Display Butterfly Pattern

class MyPattern 
	# Include Space of given size
	def space(size) 
		counter = 0
		while (counter < size) 
			print(" ")
			counter += 1
		end
	end
	# Include Symbol
	def print_symbol(size) 
		counter = 0
		while (counter < size) 
			if (counter == 0 ||
				counter + 1 == size) 
				print("⌖")
			else 
				print("⁖")
			end
			counter += 1
		end
	end
	def butterfly_pattern(size) 
		print("\n Size  :", size ," \n")
		i = 0
		 # Display the result of top half shell
		while (i < size) 
			self.space(i)
			self.print_symbol(i)
			self.space((size * 4) - (i * 4))
			self.print_symbol(i)
			print("\n")
			i += 1
		end
		i = 0
		 # Display the result of bottom half shell
		while (i < size) 
			self.space(size - i)
			self.print_symbol(size - i)
			self.space((i * 4))
			self.print_symbol(size - i)
			print("\n")
			i += 1
		end
	end
end
def main() 
	obj = MyPattern.new()
	obj.butterfly_pattern(4)
	obj.butterfly_pattern(5)
	obj.butterfly_pattern(7)
end
main()

Output

 Size  :4 
                
 ⌖            ⌖
  ⌖⌖        ⌖⌖
   ⌖⁖⌖    ⌖⁖⌖
    ⌖⁖⁖⌖⌖⁖⁖⌖
   ⌖⁖⌖    ⌖⁖⌖
  ⌖⌖        ⌖⌖
 ⌖            ⌖

 Size  :5 
                    
 ⌖                ⌖
  ⌖⌖            ⌖⌖
   ⌖⁖⌖        ⌖⁖⌖
    ⌖⁖⁖⌖    ⌖⁖⁖⌖
     ⌖⁖⁖⁖⌖⌖⁖⁖⁖⌖
    ⌖⁖⁖⌖    ⌖⁖⁖⌖
   ⌖⁖⌖        ⌖⁖⌖
  ⌖⌖            ⌖⌖
 ⌖                ⌖

 Size  :7 
                            
 ⌖                        ⌖
  ⌖⌖                    ⌖⌖
   ⌖⁖⌖                ⌖⁖⌖
    ⌖⁖⁖⌖            ⌖⁖⁖⌖
     ⌖⁖⁖⁖⌖        ⌖⁖⁖⁖⌖
      ⌖⁖⁖⁖⁖⌖    ⌖⁖⁖⁖⁖⌖
       ⌖⁖⁖⁖⁖⁖⌖⌖⁖⁖⁖⁖⁖⌖
      ⌖⁖⁖⁖⁖⌖    ⌖⁖⁖⁖⁖⌖
     ⌖⁖⁖⁖⌖        ⌖⁖⁖⁖⌖
    ⌖⁖⁖⌖            ⌖⁖⁖⌖
   ⌖⁖⌖                ⌖⁖⌖
  ⌖⌖                    ⌖⌖
 ⌖                        ⌖
/*
  Scala Program
  Display Butterfly Pattern
*/
class MyPattern {
	/*Include Space of given size*/
	def space(size: Int): Unit = {
		var counter: Int = 0;
		while (counter < size) {
			print(" ");
			counter += 1;
		}
	}
	/*Include Symbol*/
	def print_symbol(size: Int): Unit = {
		var counter: Int = 0;
		while (counter < size) {
			if (counter == 0 ||
				counter + 1 == size) {
				print("⌖");
			} else {
				print("⁖");
			}
			counter += 1;
		}
	}
	def butterfly_pattern(size: Int): Unit = {
		print("\n Size : " + size + " \n");
		var i: Int = 0;

		//Display the result of top half shell
		while (i < size) {
			this.space(i);
			this.print_symbol(i);
			this.space((size * 4) - (i * 4));
			this.print_symbol(i);
			print("\n");
			i += 1;
		}
		i = 0;

		//Display the result of bottom half shell
		while (i < size) {
			this.space(size - i);
			this.print_symbol(size - i);
			this.space((i * 4));
			this.print_symbol(size - i);
			print("\n");
			i += 1;
		}
	}
}
object Main {
	def main(args: Array[String]): Unit = {
		val obj: MyPattern = new MyPattern();
		obj.butterfly_pattern(4);
		obj.butterfly_pattern(5);
		obj.butterfly_pattern(7);
	}
}

Output

 Size : 4

 ⌖            ⌖
  ⌖⌖        ⌖⌖
   ⌖⁖⌖    ⌖⁖⌖
    ⌖⁖⁖⌖⌖⁖⁖⌖
   ⌖⁖⌖    ⌖⁖⌖
  ⌖⌖        ⌖⌖
 ⌖            ⌖

 Size : 5

 ⌖                ⌖
  ⌖⌖            ⌖⌖
   ⌖⁖⌖        ⌖⁖⌖
    ⌖⁖⁖⌖    ⌖⁖⁖⌖
     ⌖⁖⁖⁖⌖⌖⁖⁖⁖⌖
    ⌖⁖⁖⌖    ⌖⁖⁖⌖
   ⌖⁖⌖        ⌖⁖⌖
  ⌖⌖            ⌖⌖
 ⌖                ⌖

 Size : 7

 ⌖                        ⌖
  ⌖⌖                    ⌖⌖
   ⌖⁖⌖                ⌖⁖⌖
    ⌖⁖⁖⌖            ⌖⁖⁖⌖
     ⌖⁖⁖⁖⌖        ⌖⁖⁖⁖⌖
      ⌖⁖⁖⁖⁖⌖    ⌖⁖⁖⁖⁖⌖
       ⌖⁖⁖⁖⁖⁖⌖⌖⁖⁖⁖⁖⁖⌖
      ⌖⁖⁖⁖⁖⌖    ⌖⁖⁖⁖⁖⌖
     ⌖⁖⁖⁖⌖        ⌖⁖⁖⁖⌖
    ⌖⁖⁖⌖            ⌖⁖⁖⌖
   ⌖⁖⌖                ⌖⁖⌖
  ⌖⌖                    ⌖⌖
 ⌖                        ⌖
/*
  Swift Program
  Display Butterfly Pattern
*/
class MyPattern {
	/*Include Space of given size*/
	func space(_ size: Int) {
		var counter = 0;
		while (counter < size) {
			print(" ", terminator: "");
			counter += 1;
		}
	}
	/*Include Symbol*/
	func print_symbol(_ size: Int) {
		var counter = 0;
		while (counter < size) {
			if (counter == 0 ||
				counter + 1 == size) {
				print("⌖", terminator: "");
			} else {
				print("⁖", terminator: "");
			}
			counter += 1;
		}
	}
	func butterfly_pattern(_ size: Int) {
		print("\n Size : ", size ," \n", terminator: "");
		var i = 0;
		//Display the result of top half shell
		while (i < size) {
			self.space(i);
			self.print_symbol(i);
			self.space((size * 4) - (i * 4));
			self.print_symbol(i);
			print("\n", terminator: "");
			i += 1;
		}
		i = 0;
		//Display the result of bottom half shell
		while (i < size) {
			self.space(size - i);
			self.print_symbol(size - i);
			self.space((i * 4));
			self.print_symbol(size - i);
			print("\n", terminator: "");
			i += 1;
		}
	}
}
func main() {
	let obj = MyPattern();
	obj.butterfly_pattern(4);
	obj.butterfly_pattern(5);
	obj.butterfly_pattern(7);
}
main();

Output

 Size :  4

 ⌖            ⌖
  ⌖⌖        ⌖⌖
   ⌖⁖⌖    ⌖⁖⌖
    ⌖⁖⁖⌖⌖⁖⁖⌖
   ⌖⁖⌖    ⌖⁖⌖
  ⌖⌖        ⌖⌖
 ⌖            ⌖

 Size :  5

 ⌖                ⌖
  ⌖⌖            ⌖⌖
   ⌖⁖⌖        ⌖⁖⌖
    ⌖⁖⁖⌖    ⌖⁖⁖⌖
     ⌖⁖⁖⁖⌖⌖⁖⁖⁖⌖
    ⌖⁖⁖⌖    ⌖⁖⁖⌖
   ⌖⁖⌖        ⌖⁖⌖
  ⌖⌖            ⌖⌖
 ⌖                ⌖

 Size :  7

 ⌖                        ⌖
  ⌖⌖                    ⌖⌖
   ⌖⁖⌖                ⌖⁖⌖
    ⌖⁖⁖⌖            ⌖⁖⁖⌖
     ⌖⁖⁖⁖⌖        ⌖⁖⁖⁖⌖
      ⌖⁖⁖⁖⁖⌖    ⌖⁖⁖⁖⁖⌖
       ⌖⁖⁖⁖⁖⁖⌖⌖⁖⁖⁖⁖⁖⌖
      ⌖⁖⁖⁖⁖⌖    ⌖⁖⁖⁖⁖⌖
     ⌖⁖⁖⁖⌖        ⌖⁖⁖⁖⌖
    ⌖⁖⁖⌖            ⌖⁖⁖⌖
   ⌖⁖⌖                ⌖⁖⌖
  ⌖⌖                    ⌖⌖
 ⌖                        ⌖


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