Posted on by Kalkicode
Code Pattern

# Print Left Arrow Patterns

In this article, we will discuss the problem of printing left arrow patterns using C programming. We will provide an explanation of the problem, the algorithm to solve it, and the corresponding code. Additionally, we will include suitable examples and discuss the output generated by the code.

## Problem Statement

The problem is to print left arrow patterns of various sizes. The left arrow pattern consists of asterisks (*) arranged in a specific shape. The pattern starts with a single asterisk at the top and gradually increases in size until the middle row. Then, it decreases in size until a single asterisk at the bottom. Each row is indented based on its position in the pattern.

## Explanation with Example

Let's consider an example to understand the problem. We want to print a left arrow pattern of size 3.

```    *
**
***
**
*
```

In the example, we can observe that the pattern starts with a single asterisk at the top and increases in size until the middle row. Then, it decreases in size until a single asterisk at the bottom. The rows are indented to create the left arrow shape.

## Algorithm and Pseudocode

To solve this problem, we can use the following algorithm:

1. Define a function to print spaces. This function will take the number of spaces as input and print the corresponding number of spaces.
2. Define a function to print asterisks. This function will take the number of asterisks as input and print the corresponding number of asterisks.
3. Define the main function.
4. Inside the main function, define a function to display the left arrow pattern. This function will take the size of the pattern as input.
5. Inside the left arrow function, initialize a loop variable i to 0.
6. Start a loop from i = 0 to i < size.
7. Inside the loop, call the space function with the argument (size * 2) - (i * 2) to print the required number of spaces.
8. Call the print_star function with the argument i to print the required number of asterisks.
9. Print a newline character to move to the next line.
10. Repeat steps 6-9 for the second half of the pattern, starting from i = 0 to i < size.
11. End the left arrow function.
12. Inside the main function, call the left arrow function with different sizes to test the pattern.
13. Return 0 to exit the main function.

Here is the pseudocode for the algorithm:

``````
function space(size):
for counter from 0 to size:
print " "

function print_star(size):
for counter from 0 to size:
print "*"

function left_arrow(size):
print "Size: " + size
for i from 0 to size:
space((size * 2) - (i * 2))
print_star(i)
print newline
for i from 0 to size:
space(i * 2)
print_star(size - i)
print newline

main():
left_arrow(3)
left_arrow(4)
left_arrow(7)
return 0```
```

## Code Solution

``````//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++) {

printf(" ");
}
}
/*Include Space of given size*/
void print_star(int size) {

int counter = 0;

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

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++) {

cout << " ";
}
}
/*Include Space of given size*/
void print_star(int size) {
int counter = 0;
for (counter = 0; counter < size; counter++) {

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++) {

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

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

int counter = 0;

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

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++) {

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

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++) {

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

/*Include Space of given size*/
print_star(size) {
var counter = 0;
for (counter = 0; counter < size; counter++) {

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

*
**
***
****
*****
******
*******
******
*****
****
***
**
*``````

The time complexity of the code is O(n^2), where n is the size of the pattern. This is because there are nested loops that iterate up to the size of the pattern.

With this explanation, you should now have a clear understanding of the problem, the algorithm, the code, and the output produced for different test cases.

## Another complicated arrow

We will explore the problem of printing left arrow patterns using a C program. Left arrow patterns consist of arrows pointing to the left, formed using a combination of spaces and symbols. The program will take two inputs: the size of the arrow and the number of repetitions.

## Problem Statement

The task is to create a program that can display left arrow patterns of a given size and repetition. The size determines the length and width of the arrow, while the repetition specifies how many times the pattern should be repeated vertically.

For example, let's consider a size of 4 and a repetition of 5:

```      <     <     <     <     <
<<    <<    <<    <<    <<
<-<   <-<   <-<   <-<   <-<
<--<  <--<  <--<  <--<  <--<
<-<   <-<   <-<   <-<   <-<
<<    <<    <<    <<    <<
<     <     <     <     <
```

The arrows are formed using the less-than symbol (<) and hyphens (-). Each repetition is displayed vertically, creating a shell-like pattern.

## Algorithm and Pseudocode

Let's understand the algorithm to solve this problem:

1. Define a function to print spaces. This function takes the size as a parameter and prints the required number of spaces.
2. Define a function to print the arrow symbol. This function takes the size as a parameter and prints the arrow symbol, which is a combination of hyphens and the less-than symbol. The first and last positions contain the less-than symbol, while the rest are hyphens.
3. Define a function to print the left arrow pattern. This function takes the size and repetition as parameters.
4. Inside the function, iterate from 0 to size - 1. This represents the top half of the arrow.
5. Print spaces based on the current iteration.
6. Print the arrow symbol for the current iteration.
7. For each repetition, print spaces and the arrow symbol again.
8. Print a new line.
9. Iterate from 0 to size - 1 again. This represents the bottom half of the arrow.
10. Print spaces based on the current iteration.
11. Print the arrow symbol for the current iteration.
12. For each repetition, print spaces and the arrow symbol again.
13. Print a new line.
14. End of the function.
15. In the main function, call the double_left_arrow function with different test cases to demonstrate the pattern.

Here is the pseudocode for the main function:

``````
function space(size):
for counter from 0 to size - 1:
print a space

function print_symbol(size):
for counter from 0 to size - 1:
if counter is 0 or counter + 1 is equal to size:
print a less-than symbol
else:
print a hyphen

function double_left_arrow(size, n):
for i from 0 to size - 1:
space((size * 2) - (i * 2))
print_symbol(i)
for j from 1 to n - 1:
space((size + (size / 2)) - (i + 1) + 1)
print_symbol(i)
print a new line
for i from 0 to size - 1:
space(i * 2)
print_symbol(size - i)
for j from 1 to n - 1:
space((size / 2) + i)
print_symbol(size - i)
print a new line

function main():
double_left_arrow(4, 5)
double_left_arrow(5, 3)
double_left_arrow(7, 2)```
```
``````//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++) {

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++) {

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++) {
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++) {

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++) {

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

<         <
<<        <<
<-<       <-<
<--<      <--<
<---<     <---<
<----<    <----<
<-----<   <-----<
<----<    <----<
<---<     <---<
<--<      <--<
<-<       <-<
<<        <<
<         <``````

The time complexity of the code is O(size * n), where size is the size of the arrow and n is the number of repetitions. The nested loops iterate over the size and n values, resulting in a linear relationship between the input size and the number of iterations.

## 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.

Categories
Relative Post