Print Left Arrow Patterns

Here given code implementation process.

//C Program 
//Print Left Arrow 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 Space of given size*/
void print_star(int size) {

  int counter = 0;

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

    //Add space
    printf("*");
  }
}
//Display the left arrow of given size
void left_arrow(int size) {

  
  printf("\n Size : %d \n", size);
  
  int i=0;

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

    space((size*2)-(i*2));

    print_star(i);
    printf("\n");
  } 
  for(i=0;i<size;i++){

    space(i*2);

    print_star(size-i);

    printf("\n"); 
  } 
}


int main() {
  //Test Cases
  left_arrow(3);
  left_arrow(4);
  left_arrow(7);
  return 0;
}

Output

 Size : 3

    *
  **
***
  **
    *

 Size : 4

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

 Size : 7

            *
          **
        ***
      ****
    *****
  ******
*******
  ******
    *****
      ****
        ***
          **
            *
/*
  C++ Program
  Print Left Arrow 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 Space of given size*/
  void print_star(int size) {
    int counter = 0;
    for (counter = 0; counter < size; counter++) {
      //Add space

      cout << "*";
    }
  }
  //Display the left arrow of given size
  void left_arrow(int size) {
    cout << "\n Size : " << size << " \n";
    int i = 0;
    for (i = 0; i < size; i++) {
      this->space((size *2) - (i *2));
      this->print_star(i);
      cout << "\n";
    }
    for (i = 0; i < size; i++) {
      this->space(i *2);
      this->print_star(size - i);
      cout << "\n";
    }
  }
};
int main() {
  MyPattern obj =  MyPattern();
  //Test Cases
  obj.left_arrow(3);
  obj.left_arrow(4);
  obj.left_arrow(7);
  return 0;
}

Output

 Size : 3

    *
  **
***
  **
    *

 Size : 4

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

 Size : 7

            *
          **
        ***
      ****
    *****
  ******
*******
  ******
    *****
      ****
        ***
          **
            *
/*
  Java Program
  Print Left Arrow 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 Space of given size*/
  public void print_star(int size) {

    int counter = 0;

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

      //Add space
      System.out.print("*");
    }
  }
  //Display the left arrow of given size
  public void left_arrow(int size) {

    
    System.out.print("\n Size : "+size+" \n");
    
    int i=0;

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

      space((size*2)-(i*2));

      print_star(i);
      System.out.print("\n");
    } 
    for(i=0;i<size;i++){

      space(i*2);

      print_star(size-i);

      System.out.print("\n"); 
    } 
  }

  public static void main(String[] args) {

    MyPattern obj = new MyPattern();
    //Test Cases
    obj.left_arrow(3);
    obj.left_arrow(4);
    obj.left_arrow(7);
  }
}

Output

 Size : 3

    *
  **
***
  **
    *

 Size : 4

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

 Size : 7

            *
          **
        ***
      ****
    *****
  ******
*******
  ******
    *****
      ****
        ***
          **
            *
/*
  C# Program
  Print Left Arrow 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 Space of given size*/
  public void print_star(int size) {
    int counter = 0;
    for (counter = 0; counter < size; counter++) {
      Console.Write("*");
    }
  }
  //Display the left arrow of given size
  public void left_arrow(int size) {
    Console.Write("\n Size : " + size + " \n");
    int i = 0;
    for (i = 0; i < size; i++) {
      space((size * 2) - (i * 2));
      print_star(i);
      Console.Write("\n");
    }
    for (i = 0; i < size; i++) {
      space(i * 2);
      print_star(size - i);
      Console.Write("\n");
    }
  }
  public static void Main(String[] args) {
    MyPattern obj = new MyPattern();
    obj.left_arrow(3);
    obj.left_arrow(4);
    obj.left_arrow(7);
  }
}

Output

 Size : 3

    *
  **
***
  **
    *

 Size : 4

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

 Size : 7

            *
          **
        ***
      ****
    *****
  ******
*******
  ******
    *****
      ****
        ***
          **
            *
<?php
/*
  Php Program
  Print Left Arrow Pattern
*/
class MyPattern {
  /*Include Space of given size*/
  public  function space($size) {
    $counter = 0;
    for ($counter = 0; $counter < $size; $counter++) {
      //Add space

      echo(" ");
    }
  }
  /*Include Space of given size*/
  public  function print_star($size) {
    $counter = 0;
    for ($counter = 0; $counter < $size; $counter++) {
      //Add space

      echo("*");
    }
  }
  //Display the left arrow of given size
  public  function left_arrow($size) {
    echo("\n Size : ". $size ." \n");
    $i = 0;
    for ($i = 0; $i < $size; $i++) {
      $this->space(($size *2) - ($i *2));
      $this->print_star($i);
      echo("\n");
    }
    for ($i = 0; $i < $size; $i++) {
      $this->space($i *2);
      $this->print_star($size - $i);
      echo("\n");
    }
  }
}

function main() {
  $obj = new MyPattern();
  //Test Cases
  $obj->left_arrow(3);
  $obj->left_arrow(4);
  $obj->left_arrow(7);

}
main();

Output

 Size : 3

    *
  **
***
  **
    *

 Size : 4

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

 Size : 7

            *
          **
        ***
      ****
    *****
  ******
*******
  ******
    *****
      ****
        ***
          **
            *
/*
  Node Js Program
  Print Left Arrow 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 Space of given size*/
  print_star(size) {
    var counter = 0;
    for (counter = 0; counter < size; counter++) {
      //Add space

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

  //Display the left arrow of given size
  left_arrow(size) {
    process.stdout.write("\n Size : " + size + " \n");
    var i = 0;
    for (i = 0; i < size; i++) {
      this.space((size *2) - (i *2));
      this.print_star(i);
      process.stdout.write("\n");
    }

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

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

main();

Output

 Size : 3

    *
  **
***
  **
    *

 Size : 4

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

 Size : 7

            *
          **
        ***
      ****
    *****
  ******
*******
  ******
    *****
      ****
        ***
          **
            *
#   Python 3 Program
#   Print Left Arrow Pattern

class MyPattern :
  # Include Space of given size
  def space(self, size) :
    counter = 0
    while (counter < size) :
      print(" ", end = "")
      counter += 1
    
  
  # Include Space of given size
  def print_star(self, size) :
    counter = 0
    while (counter < size) :
      print("*", end = "")
      counter += 1
    
  
  # Display the left arrow of given size
  def left_arrow(self, size) :
    print("\n Size : ", size ," \n", end = "")
    i = 0
    while (i < size) :
      self.space((size * 2) - (i * 2))
      self.print_star(i)
      print("\n", end = "")
      i += 1
    
    i = 0
    while (i < size) :
      self.space(i * 2)
      self.print_star(size - i)
      print("\n", end = "")
      i += 1
    
  

def main() :
  obj = MyPattern()
  obj.left_arrow(3)
  obj.left_arrow(4)
  obj.left_arrow(7)


if __name__ == "__main__":
  main()

Output

 Size :  3

    *
  **
***
  **
    *

 Size :  4

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

 Size :  7

            *
          **
        ***
      ****
    *****
  ******
*******
  ******
    *****
      ****
        ***
          **
            *
#   Ruby Program
#   Print Left Arrow Pattern

class MyPattern 
  # Include Space of given size 
  def space(size) 
    counter = 0
    while (counter < size) 
      print(" ")
      counter += 1
    end
  end
  # Include Space of given size
  def print_star(size) 
    counter = 0
    while (counter < size) 
      print("*")
      counter += 1
    end
  end
   # Display the left arrow of given size
  def left_arrow(size) 
    print("\n Size  :", size ," \n")
    i = 0
    while (i < size) 
      self.space((size * 2) - (i * 2))
      self.print_star(i)
      print("\n")
      i += 1
    end
    i = 0
    while (i < size) 
      self.space(i * 2)
      self.print_star(size - i)
      print("\n")
      i += 1
    end
  end
end
def main() 
  obj = MyPattern.new()
  obj.left_arrow(3)
  obj.left_arrow(4)
  obj.left_arrow(7)
end
main()

Output

 Size  :3 
      
    *
  **
***
  **
    *

 Size  :4 
        
      *
    **
  ***
****
  ***
    **
      *

 Size  :7 
              
            *
          **
        ***
      ****
    *****
  ******
*******
  ******
    *****
      ****
        ***
          **
            *
/*
  Scala Program
  Print Left Arrow Pattern
*/
class MyPattern {
  /*Include Space of given size*/
  def space(size: Int): Unit = {
    var counter: Int = 0;
    while (counter < size) {
      print(" ");
      counter += 1;
    }
  }
  /*Include Space of given size*/
  def print_star(size: Int): Unit = {
    var counter: Int = 0;
    while (counter < size) {
      print("*");
      counter += 1;
    }
  }
  //Display the left arrow of given size
  def left_arrow(size: Int): Unit = {
    print("\n Size : " + size + " \n");
    var i: Int = 0;
    while (i < size) {
      this.space((size * 2) - (i * 2));
      this.print_star(i);
      print("\n");
      i += 1;
    }
    i = 0;
    while (i < size) {
      this.space(i * 2);
      this.print_star(size - i);
      print("\n");
      i += 1;
    }
  }
}
object Main {
  def main(args: Array[String]): Unit = {
    val obj: MyPattern = new MyPattern();
    obj.left_arrow(3);
    obj.left_arrow(4);
    obj.left_arrow(7);
  }
}

Output

 Size : 3

    *
  **
***
  **
    *

 Size : 4

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

 Size : 7

            *
          **
        ***
      ****
    *****
  ******
*******
  ******
    *****
      ****
        ***
          **
            *
/*
  Swift Program
  Print Left Arrow Pattern
*/
class MyPattern {
  /*Include Space of given size*/
  func space(_ size: Int) {
    var counter = 0;
    while (counter < size) {
      print(" ", terminator: "");
      counter += 1;
    }
  }
  /*Include Space of given size*/
  func print_star(_ size: Int) {
    var counter = 0;
    while (counter < size) {
      print("*", terminator: "");
      counter += 1;
    }
  }
  //Display the left arrow of given size
  func left_arrow(_ size: Int) {
    print("\n Size : ", size ," \n", terminator: "");
    var i = 0;
    while (i < size) {
      self.space((size * 2) - (i * 2));
      self.print_star(i);
      print("\n", terminator: "");
      i += 1;
    }
    i = 0;
    while (i < size) {
      self.space(i * 2);
      self.print_star(size - i);
      print("\n", terminator: "");
      i += 1;
    }
  }
}
func main() {
  let obj = MyPattern();
  obj.left_arrow(3);
  obj.left_arrow(4);
  obj.left_arrow(7);
}
main();

Output

 Size :  3

    *
  **
***
  **
    *

 Size :  4

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

 Size :  7

            *
          **
        ***
      ****
    *****
  ******
*******
  ******
    *****
      ****
        ***
          **
            *
//C Program 
//Display left arrow pattern in given size
#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("-");
    }
   
  }
}
//Display the left arrow of given size
void double_left_arrow(int size ,int n) {

  
  printf("\n Size : %d  N : %d \n", size,n);
  
  int i=0,j=0;
  //Display the result of top half shell
  for(i=0;i<size;i++){

    space((size*2)-(i*2));

    print_symbol(i);
    for (j = 1; j < n; ++j)
    {
      space((size+(size/2))-(i+1)+1);

     print_symbol(i); 
    }
    

    printf("\n");
  } 
  //Display the result of bottom half shell
  for(i=0;i<size;i++){

    space(i*2);

    print_symbol(size-i);
    for (j = 1; j < n; ++j)
    {
      space((size/2)+i);

      print_symbol(size-i);
    }


    printf("\n"); 
  } 
}


int main() {
  //Test Cases
  double_left_arrow(4,5);
  double_left_arrow(5,3);
  double_left_arrow(7,2);
  return 0;
}

Output

 Size : 4  N : 5

      <     <     <     <     <
    <<    <<    <<    <<    <<
  <-<   <-<   <-<   <-<   <-<
<--<  <--<  <--<  <--<  <--<
  <-<   <-<   <-<   <-<   <-<
    <<    <<    <<    <<    <<
      <     <     <     <     <

 Size : 5  N : 3

        <      <      <
      <<     <<     <<
    <-<    <-<    <-<
  <--<   <--<   <--<
<---<  <---<  <---<
  <--<   <--<   <--<
    <-<    <-<    <-<
      <<     <<     <<
        <      <      <

 Size : 7  N : 2

            <         <
          <<        <<
        <-<       <-<
      <--<      <--<
    <---<     <---<
  <----<    <----<
<-----<   <-----<
  <----<    <----<
    <---<     <---<
      <--<      <--<
        <-<       <-<
          <<        <<
            <         <
/*
  C++ Program
  Display left arrow pattern in given size
*/
#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 << "-";
      }
    }
  }
  //Display the left arrow of given size
  void double_left_arrow(int size, int n) {
    cout << "\n Size : " << size << " N : " << n << " \n";
    int i = 0, j = 0;
    //Display the result of top half shell

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

    for (i = 0; i < size; i++) {
      this->space(i *2);
      this->print_symbol(size - i);
      for (j = 1; j < n; ++j) {
        this->space((size / 2) + i);
        this->print_symbol(size - i);
      }
      cout << "\n";
    }
  }
};
int main() {
  MyPattern obj =  MyPattern();
  //Test Cases
  obj.double_left_arrow(4, 5);
  obj.double_left_arrow(5, 3);
  obj.double_left_arrow(7, 2);
  return 0;
}

Output

 Size : 4 N : 5

      <     <     <     <     <
    <<    <<    <<    <<    <<
  <-<   <-<   <-<   <-<   <-<
<--<  <--<  <--<  <--<  <--<
  <-<   <-<   <-<   <-<   <-<
    <<    <<    <<    <<    <<
      <     <     <     <     <

 Size : 5 N : 3

        <      <      <
      <<     <<     <<
    <-<    <-<    <-<
  <--<   <--<   <--<
<---<  <---<  <---<
  <--<   <--<   <--<
    <-<    <-<    <-<
      <<     <<     <<
        <      <      <

 Size : 7 N : 2

            <         <
          <<        <<
        <-<       <-<
      <--<      <--<
    <---<     <---<
  <----<    <----<
<-----<   <-----<
  <----<    <----<
    <---<     <---<
      <--<      <--<
        <-<       <-<
          <<        <<
            <         <
/*
  Java Program
  Display left arrow pattern in given size
*/

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("-");
      }
    }
  }
  //Display the left arrow of given size
  public void double_left_arrow(int size, int n) {
    System.out.print("\n Size : "+size+" N : "+n+" \n" );
  
    int i=0,j=0;
    //Display the result of top half shell
    for(i=0;i<size;i++){

      space((size*2)-(i*2));

      print_symbol(i);
      for (j = 1; j < n; ++j)
      {
        space((size+(size/2))-(i+1)+1);

        print_symbol(i); 
      }
      

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

      space(i*2);

      print_symbol(size-i);
      for (j = 1; j < n; ++j)
      {
        space((size/2)+i);

        print_symbol(size-i);
      }
      System.out.print("\n");
    } 
  }
  public static void main(String[] args) {

    MyPattern obj = new MyPattern();
    //Test Cases
    obj.double_left_arrow(4,5);
    obj.double_left_arrow(5,3);
    obj.double_left_arrow(7,2);
  }
}

Output

 Size : 4 N : 5

      <     <     <     <     <
    <<    <<    <<    <<    <<
  <-<   <-<   <-<   <-<   <-<
<--<  <--<  <--<  <--<  <--<
  <-<   <-<   <-<   <-<   <-<
    <<    <<    <<    <<    <<
      <     <     <     <     <

 Size : 5 N : 3

        <      <      <
      <<     <<     <<
    <-<    <-<    <-<
  <--<   <--<   <--<
<---<  <---<  <---<
  <--<   <--<   <--<
    <-<    <-<    <-<
      <<     <<     <<
        <      <      <

 Size : 7 N : 2

            <         <
          <<        <<
        <-<       <-<
      <--<      <--<
    <---<     <---<
  <----<    <----<
<-----<   <-----<
  <----<    <----<
    <---<     <---<
      <--<      <--<
        <-<       <-<
          <<        <<
            <         <
/*
  C# Program
  Display left arrow pattern in given size
*/
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("-");
      }
    }
  }
  //Display the left arrow of given size
  public void double_left_arrow(int size, int n) {
    Console.Write("\n Size : " + size + " N : " + n + " \n");
    int i = 0, j = 0;
    //Display the result of top half shell

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

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

Output

 Size : 4 N : 5

      <     <     <     <     <
    <<    <<    <<    <<    <<
  <-<   <-<   <-<   <-<   <-<
<--<  <--<  <--<  <--<  <--<
  <-<   <-<   <-<   <-<   <-<
    <<    <<    <<    <<    <<
      <     <     <     <     <

 Size : 5 N : 3

        <      <      <
      <<     <<     <<
    <-<    <-<    <-<
  <--<   <--<   <--<
<---<  <---<  <---<
  <--<   <--<   <--<
    <-<    <-<    <-<
      <<     <<     <<
        <      <      <

 Size : 7 N : 2

            <         <
          <<        <<
        <-<       <-<
      <--<      <--<
    <---<     <---<
  <----<    <----<
<-----<   <-----<
  <----<    <----<
    <---<     <---<
      <--<      <--<
        <-<       <-<
          <<        <<
            <         <
<?php
/*
  Php Program
  Display left arrow pattern in given size
*/
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("-");
      }
    }
  }
  //Display the left arrow of given size

  public  function double_left_arrow($size, $n) {
    echo("\n Size : ". $size ." N : ". $n ." \n");
    $i = 0;
    $j = 0;
    //Display the result of top half shell

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

    for ($i = 0; $i < $size; $i++) {
      $this->space($i *2);
      $this->print_symbol($size - $i);
      for ($j = 1; $j < $n; ++$j) {
        $this->space((intval($size / 2)) + $i);
        $this->print_symbol($size - $i);
      }
      echo("\n");
    }
  }
}

function main() {
  $obj = new MyPattern();
  //Test Cases
  $obj->double_left_arrow(4, 5);
  $obj->double_left_arrow(5, 3);
  $obj->double_left_arrow(7, 2);

}
main();

Output

 Size : 4 N : 5

      <     <     <     <     <
    <<    <<    <<    <<    <<
  <-<   <-<   <-<   <-<   <-<
<--<  <--<  <--<  <--<  <--<
  <-<   <-<   <-<   <-<   <-<
    <<    <<    <<    <<    <<
      <     <     <     <     <

 Size : 5 N : 3

        <      <      <
      <<     <<     <<
    <-<    <-<    <-<
  <--<   <--<   <--<
<---<  <---<  <---<
  <--<   <--<   <--<
    <-<    <-<    <-<
      <<     <<     <<
        <      <      <

 Size : 7 N : 2

            <         <
          <<        <<
        <-<       <-<
      <--<      <--<
    <---<     <---<
  <----<    <----<
<-----<   <-----<
  <----<    <----<
    <---<     <---<
      <--<      <--<
        <-<       <-<
          <<        <<
            <         <
/*
  Node Js Program
  Display left arrow pattern in given size
*/
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("-");
      }
    }
  }

  //Display the left arrow of given size
  double_left_arrow(size, n) {
    process.stdout.write("\n Size : " + size + " N : " + n + " \n");
    var i = 0;
    var j = 0;
    //Display the result of top half shell

    for (i = 0; i < size; i++) {
      this.space((size *2) - (i *2));
      this.print_symbol(i);
      for (j = 1; j < n; ++j) {
        this.space((size + (parseInt(size / 2))) - (i + 1) + 1);
        this.print_symbol(i);
      }

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

    //Display the result of bottom half shell

    for (i = 0; i < size; i++) {
      this.space(i *2);
      this.print_symbol(size - i);
      for (j = 1; j < n; ++j) {
        this.space((parseInt(size / 2)) + i);
        this.print_symbol(size - i);
      }

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

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

main();

Output

 Size : 4 N : 5

      <     <     <     <     <
    <<    <<    <<    <<    <<
  <-<   <-<   <-<   <-<   <-<
<--<  <--<  <--<  <--<  <--<
  <-<   <-<   <-<   <-<   <-<
    <<    <<    <<    <<    <<
      <     <     <     <     <

 Size : 5 N : 3

        <      <      <
      <<     <<     <<
    <-<    <-<    <-<
  <--<   <--<   <--<
<---<  <---<  <---<
  <--<   <--<   <--<
    <-<    <-<    <-<
      <<     <<     <<
        <      <      <

 Size : 7 N : 2

            <         <
          <<        <<
        <-<       <-<
      <--<      <--<
    <---<     <---<
  <----<    <----<
<-----<   <-----<
  <----<    <----<
    <---<     <---<
      <--<      <--<
        <-<       <-<
          <<        <<
            <         <
#   Python 3 Program
#   Display left arrow pattern in given size

class MyPattern :
  # Include Space of given size
  def space(self, size) :
    counter = 0
    counter = 0
    while (counter < size) :
      print(" ", end = "")
      counter += 1
    
  
  # Include Symbol
  def print_symbol(self, size) :
    counter = 0
    counter = 0
    while (counter < size) :
      if (counter == 0 or counter + 1 == size) :
        print("<", end = "")
      else :
        print("-", end = "")
      
      counter += 1
    
  
  # Display the left arrow of given size
  def double_left_arrow(self, size, n) :
    print("\n Size : ", size ," N : ", n ," \n", end = "")
    i = 0
    j = 0
    # Display the result of top half shell
    while (i < size) :
      self.space((size * 2) - (i * 2))
      self.print_symbol(i)
      j = 1
      while (j < n) :
        self.space((size + (int(size / 2))) - (i + 1) + 1)
        self.print_symbol(i)
        j += 1
      
      print("\n", end = "")
      i += 1
    
    # Display the result of bottom half shell
    i = 0
    while (i < size) :
      self.space(i * 2)
      self.print_symbol(size - i)
      j = 1
      while (j < n) :
        self.space((int(size / 2)) + i)
        self.print_symbol(size - i)
        j += 1
      
      print("\n", end = "")
      i += 1
    
  

def main() :
  obj = MyPattern()
  obj.double_left_arrow(4, 5)
  obj.double_left_arrow(5, 3)
  obj.double_left_arrow(7, 2)


if __name__ == "__main__":
  main()

Output

 Size :  4  N :  5

      <     <     <     <     <
    <<    <<    <<    <<    <<
  <-<   <-<   <-<   <-<   <-<
<--<  <--<  <--<  <--<  <--<
  <-<   <-<   <-<   <-<   <-<
    <<    <<    <<    <<    <<
      <     <     <     <     <

 Size :  5  N :  3

        <      <      <
      <<     <<     <<
    <-<    <-<    <-<
  <--<   <--<   <--<
<---<  <---<  <---<
  <--<   <--<   <--<
    <-<    <-<    <-<
      <<     <<     <<
        <      <      <

 Size :  7  N :  2

            <         <
          <<        <<
        <-<       <-<
      <--<      <--<
    <---<     <---<
  <----<    <----<
<-----<   <-----<
  <----<    <----<
    <---<     <---<
      <--<      <--<
        <-<       <-<
          <<        <<
            <         <
#   Ruby Program
#   Display left arrow pattern in given size

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

Output

 Size  :4 N  :5 
                                
      <     <     <     <     <
    <<    <<    <<    <<    <<
  <-<   <-<   <-<   <-<   <-<
<--<  <--<  <--<  <--<  <--<
  <-<   <-<   <-<   <-<   <-<
    <<    <<    <<    <<    <<
      <     <     <     <     <

 Size  :5 N  :3 
                        
        <      <      <
      <<     <<     <<
    <-<    <-<    <-<
  <--<   <--<   <--<
<---<  <---<  <---<
  <--<   <--<   <--<
    <-<    <-<    <-<
      <<     <<     <<
        <      <      <

 Size  :7 N  :2 
                        
            <         <
          <<        <<
        <-<       <-<
      <--<      <--<
    <---<     <---<
  <----<    <----<
<-----<   <-----<
  <----<    <----<
    <---<     <---<
      <--<      <--<
        <-<       <-<
          <<        <<
            <         <
/*
  Scala Program
  Display left arrow pattern in given size
*/
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;
    }
  }
  //Display the left arrow of given size
  def double_left_arrow(size: Int, n: Int): Unit = {
    print("\n Size : " + size + " N : " + n + " \n");
    var i: Int = 0;
    var j: Int = 0;

    //Display the result of top half shell
    i = 0;
    while (i < size) {
      space((size * 2) - (i * 2));
      print_symbol(i);
      j = 1;
      while (j < n) {
        space((size + ((size / 2).toInt)) - (i + 1) + 1);
        print_symbol(i);
        j += 1;
      }
      print("\n");
      i += 1;
    }
    //Display the result of bottom half shell
    i = 0;
    while (i < size) {
      space(i * 2);
      print_symbol(size - i);
      j = 1;
      while (j < n) {
        space(((size / 2).toInt) + i);
        print_symbol(size - i);
        j += 1;
      }
      print("\n");
      i += 1;
    }
  }
}
object Main {
  def main(args: Array[String]): Unit = {
    var obj: MyPattern = new MyPattern();
    obj.double_left_arrow(4, 5);
    obj.double_left_arrow(5, 3);
    obj.double_left_arrow(7, 2);
  }
}

Output

 Size : 4 N : 5

      <     <     <     <     <
    <<    <<    <<    <<    <<
  <-<   <-<   <-<   <-<   <-<
<--<  <--<  <--<  <--<  <--<
  <-<   <-<   <-<   <-<   <-<
    <<    <<    <<    <<    <<
      <     <     <     <     <

 Size : 5 N : 3

        <      <      <
      <<     <<     <<
    <-<    <-<    <-<
  <--<   <--<   <--<
<---<  <---<  <---<
  <--<   <--<   <--<
    <-<    <-<    <-<
      <<     <<     <<
        <      <      <

 Size : 7 N : 2

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

Output

 Size :  4  N :  5

      <     <     <     <     <
    <<    <<    <<    <<    <<
  <-<   <-<   <-<   <-<   <-<
<--<  <--<  <--<  <--<  <--<
  <-<   <-<   <-<   <-<   <-<
    <<    <<    <<    <<    <<
      <     <     <     <     <

 Size :  5  N :  3

        <      <      <
      <<     <<     <<
    <-<    <-<    <-<
  <--<   <--<   <--<
<---<  <---<  <---<
  <--<   <--<   <--<
    <-<    <-<    <-<
      <<     <<     <<
        <      <      <

 Size :  7  N :  2

            <         <
          <<        <<
        <-<       <-<
      <--<      <--<
    <---<     <---<
  <----<    <----<
<-----<   <-----<
  <----<    <----<
    <---<     <---<
      <--<      <--<
        <-<       <-<
          <<        <<
            <         <


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