Print Right Arrow Patterns
Here given code implementation process.
//C Program
//Print Right 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 right arrow of given size
void right_arrow(int size) {
printf("\n Size : %d \n", size);
int i=0;
for(i=0;i<size;i++){
space(i);
print_star(i);
printf("\n");
}
for(i=0;i<size;i++){
space(size-i);
print_star(size-i);
printf("\n");
}
}
int main() {
//Test Cases
right_arrow(3);
right_arrow(4);
right_arrow(7);
return 0;
}
Output
Size : 3
*
**
***
**
*
Size : 4
*
**
***
****
***
**
*
Size : 7
*
**
***
****
*****
******
*******
******
*****
****
***
**
*
/*
C++ Program
Print right 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 right arrow of given size
void right_arrow(int size) {
cout << "\n Size : " << size << " \n";
int i = 0;
for (i = 0; i < size; i++) {
this->space(i);
this->print_star(i);
cout << "\n";
}
for (i = 0; i < size; i++) {
this->space(size - i);
this->print_star(size - i);
cout << "\n";
}
}
};
int main() {
MyPattern obj = MyPattern();
//Test Cases
obj.right_arrow(3);
obj.right_arrow(4);
obj.right_arrow(7);
return 0;
}
Output
Size : 3
*
**
***
**
*
Size : 4
*
**
***
****
***
**
*
Size : 7
*
**
***
****
*****
******
*******
******
*****
****
***
**
*
/*
Java Program
Print right 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 right arrow of given size
public void right_arrow(int size) {
System.out.print("\n Size : "+size+" \n");
int i=0;
for(i=0;i<size;i++){
space(i);
print_star(i);
System.out.print("\n");
}
for(i=0;i<size;i++){
space(size-i);
print_star(size-i);
System.out.print("\n");
}
}
public static void main(String[] args) {
MyPattern obj = new MyPattern();
//Test Cases
obj.right_arrow(3);
obj.right_arrow(4);
obj.right_arrow(7);
}
}
Output
Size : 3
*
**
***
**
*
Size : 4
*
**
***
****
***
**
*
Size : 7
*
**
***
****
*****
******
*******
******
*****
****
***
**
*
/*
C# Program
Print right 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 right arrow of given size
public void right_arrow(int size) {
Console.Write("\n Size : " + size + " \n");
int i = 0;
for (i = 0; i < size; i++) {
space(i);
print_star(i);
Console.Write("\n");
}
for (i = 0; i < size; i++) {
space(size - i);
print_star(size - i);
Console.Write("\n");
}
}
public static void Main(String[] args) {
MyPattern obj = new MyPattern();
obj.right_arrow(3);
obj.right_arrow(4);
obj.right_arrow(7);
}
}
Output
Size : 3
*
**
***
**
*
Size : 4
*
**
***
****
***
**
*
Size : 7
*
**
***
****
*****
******
*******
******
*****
****
***
**
*
<?php
/*
Php Program
Print right 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 right arrow of given size
public function right_arrow($size) {
echo("\n Size : ". $size ." \n");
$i = 0;
for ($i = 0; $i < $size; $i++) {
$this->space($i);
$this->print_star($i);
echo("\n");
}
for ($i = 0; $i < $size; $i++) {
$this->space($size - $i);
$this->print_star($size - $i);
echo("\n");
}
}
}
function main() {
$obj = new MyPattern();
//Test Cases
$obj->right_arrow(3);
$obj->right_arrow(4);
$obj->right_arrow(7);
}
main();
Output
Size : 3
*
**
***
**
*
Size : 4
*
**
***
****
***
**
*
Size : 7
*
**
***
****
*****
******
*******
******
*****
****
***
**
*
/*
Node Js Program
Print right 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 right arrow of given size
right_arrow(size) {
process.stdout.write("\n Size : " + size + " \n");
var i = 0;
for (i = 0; i < size; i++) {
this.space(i);
this.print_star(i);
process.stdout.write("\n");
}
for (i = 0; i < size; i++) {
this.space(size - i);
this.print_star(size - i);
process.stdout.write("\n");
}
}
}
function main(args) {
var obj = new MyPattern();
//Test Cases
obj.right_arrow(3);
obj.right_arrow(4);
obj.right_arrow(7);
}
main();
Output
Size : 3
*
**
***
**
*
Size : 4
*
**
***
****
***
**
*
Size : 7
*
**
***
****
*****
******
*******
******
*****
****
***
**
*
# Python 3 Program
# Print right 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 right arrow of given size
def right_arrow(self, size) :
print("\n Size : ", size ," \n", end = "")
i = 0
while (i < size) :
self.space(i)
self.print_star(i)
print("\n", end = "")
i += 1
i = 0
while (i < size) :
self.space(size - i)
self.print_star(size - i)
print("\n", end = "")
i += 1
def main() :
obj = MyPattern()
obj.right_arrow(3)
obj.right_arrow(4)
obj.right_arrow(7)
if __name__ == "__main__":
main()
Output
Size : 3
*
**
***
**
*
Size : 4
*
**
***
****
***
**
*
Size : 7
*
**
***
****
*****
******
*******
******
*****
****
***
**
*
# Ruby Program
# Print right 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 right arrow of given size
def right_arrow(size)
print("\n Size :", size ," \n")
i = 0
while (i < size)
self.space(i)
self.print_star(i)
print("\n")
i += 1
end
i = 0
while (i < size)
self.space(size - i)
self.print_star(size - i)
print("\n")
i += 1
end
end
end
def main()
obj = MyPattern.new()
obj.right_arrow(3)
obj.right_arrow(4)
obj.right_arrow(7)
end
main()
Output
Size :3
*
**
***
**
*
Size :4
*
**
***
****
***
**
*
Size :7
*
**
***
****
*****
******
*******
******
*****
****
***
**
*
/*
Scala Program
Print right 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 right arrow of given size
def right_arrow(size: Int): Unit = {
print("\n Size : " + size + " \n");
var i: Int = 0;
while (i < size) {
this.space(i);
this.print_star(i);
print("\n");
i += 1;
}
i = 0;
while (i < size) {
this.space(size - i);
this.print_star(size - i);
print("\n");
i += 1;
}
}
}
object Main {
def main(args: Array[String]): Unit = {
val obj: MyPattern = new MyPattern();
obj.right_arrow(3);
obj.right_arrow(4);
obj.right_arrow(7);
}
}
Output
Size : 3
*
**
***
**
*
Size : 4
*
**
***
****
***
**
*
Size : 7
*
**
***
****
*****
******
*******
******
*****
****
***
**
*
/*
Swift Program
Print right 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 right arrow of given size
func right_arrow(_ size: Int) {
print("\n Size : ", size ," \n", terminator: "");
var i = 0;
while (i < size) {
self.space(i);
self.print_star(i);
print("\n", terminator: "");
i += 1;
}
i = 0;
while (i < size) {
self.space(size - i);
self.print_star(size - i);
print("\n", terminator: "");
i += 1;
}
}
}
func main() {
let obj = MyPattern();
obj.right_arrow(3);
obj.right_arrow(4);
obj.right_arrow(7);
}
main();
Output
Size : 3
*
**
***
**
*
Size : 4
*
**
***
****
***
**
*
Size : 7
*
**
***
****
*****
******
*******
******
*****
****
***
**
*
//C Program
//Print Double Right 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 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 double right arrow of given size
void double_right_arrow(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+(size/2)-i);
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+(size/2));
print_symbol(size-i);
printf("\n");
}
}
int main() {
//Test Cases
double_right_arrow(3);
double_right_arrow(6);
double_right_arrow(7);
return 0;
}
Output
Size : 3
> >
>> >>
>-> >->
>> >>
> >
Size : 6
> >
>> >>
>-> >->
>--> >-->
>---> >--->
>----> >---->
>---> >--->
>--> >-->
>-> >->
>> >>
> >
Size : 7
> >
>> >>
>-> >->
>--> >-->
>---> >--->
>----> >---->
>-----> >----->
>----> >---->
>---> >--->
>--> >-->
>-> >->
>> >>
> >
// C++ Program
// Print Double Right 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 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 double right arrow of given size
void double_right_arrow(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 + (size / 2) - i);
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 + (size / 2));
this->print_symbol(size - i);
cout << "\n";
}
}
};
int main() {
MyPattern obj = MyPattern();
//Test Case
obj.double_right_arrow(3);
obj.double_right_arrow(6);
obj.double_right_arrow(7);
return 0;
}
Output
Size : 3
> >
>> >>
>-> >->
>> >>
> >
Size : 6
> >
>> >>
>-> >->
>--> >-->
>---> >--->
>----> >---->
>---> >--->
>--> >-->
>-> >->
>> >>
> >
Size : 7
> >
>> >>
>-> >->
>--> >-->
>---> >--->
>----> >---->
>-----> >----->
>----> >---->
>---> >--->
>--> >-->
>-> >->
>> >>
> >
// Java Program
// Print Double Right Arrow Pattern
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 double right arrow of given size
public void double_right_arrow(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 + (size / 2) - i);
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 + (size / 2));
print_symbol(size - i);
System.out.print("\n");
}
}
public static void main(String[] args) {
MyPattern obj = new MyPattern();
//Test Case
obj.double_right_arrow(3);
obj.double_right_arrow(6);
obj.double_right_arrow(7);
}
}
Output
Size : 3
> >
>> >>
>-> >->
>> >>
> >
Size : 6
> >
>> >>
>-> >->
>--> >-->
>---> >--->
>----> >---->
>---> >--->
>--> >-->
>-> >->
>> >>
> >
Size : 7
> >
>> >>
>-> >->
>--> >-->
>---> >--->
>----> >---->
>-----> >----->
>----> >---->
>---> >--->
>--> >-->
>-> >->
>> >>
> >
// C# Program
// Print Double Right 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 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 double right arrow of given size
public void double_right_arrow(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 + (size / 2) - i);
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 + (size / 2));
print_symbol(size - i);
Console.Write("\n");
}
}
public static void Main(String[] args) {
MyPattern obj = new MyPattern();
obj.double_right_arrow(3);
obj.double_right_arrow(6);
obj.double_right_arrow(7);
}
}
Output
Size : 3
> >
>> >>
>-> >->
>> >>
> >
Size : 6
> >
>> >>
>-> >->
>--> >-->
>---> >--->
>----> >---->
>---> >--->
>--> >-->
>-> >->
>> >>
> >
Size : 7
> >
>> >>
>-> >->
>--> >-->
>---> >--->
>----> >---->
>-----> >----->
>----> >---->
>---> >--->
>--> >-->
>-> >->
>> >>
> >
<?php
// Php Program
// Print Double Right 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 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 double right arrow of given size
public function double_right_arrow($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 + (intval($size / 2)) - $i);
$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 + (intval($size / 2)));
$this->print_symbol($size - $i);
echo("\n");
}
}
}
function main() {
$obj = new MyPattern();
//Test Case
$obj->double_right_arrow(3);
$obj->double_right_arrow(6);
$obj->double_right_arrow(7);
}
main();
Output
Size : 3
> >
>> >>
>-> >->
>> >>
> >
Size : 6
> >
>> >>
>-> >->
>--> >-->
>---> >--->
>----> >---->
>---> >--->
>--> >-->
>-> >->
>> >>
> >
Size : 7
> >
>> >>
>-> >->
>--> >-->
>---> >--->
>----> >---->
>-----> >----->
>----> >---->
>---> >--->
>--> >-->
>-> >->
>> >>
> >
// Node Js Program
// Print Double Right 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 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 double right arrow of given size
double_right_arrow(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 + (parseInt(size / 2)) - i);
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 + (parseInt(size / 2)));
this.print_symbol(size - i);
process.stdout.write("\n");
}
}
}
function main(args) {
var obj = new MyPattern();
//Test Case
obj.double_right_arrow(3);
obj.double_right_arrow(6);
obj.double_right_arrow(7);
}
main();
Output
Size : 3
> >
>> >>
>-> >->
>> >>
> >
Size : 6
> >
>> >>
>-> >->
>--> >-->
>---> >--->
>----> >---->
>---> >--->
>--> >-->
>-> >->
>> >>
> >
Size : 7
> >
>> >>
>-> >->
>--> >-->
>---> >--->
>----> >---->
>-----> >----->
>----> >---->
>---> >--->
>--> >-->
>-> >->
>> >>
> >
# Python 3 Program
# Print Double Right Arrow Pattern
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
while (counter < size) :
if (counter == 0 or counter + 1 == size) :
print(">", end = "")
else :
print("-", end = "")
counter += 1
# Display the double right arrow of given size
def double_right_arrow(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 + (int(size / 2)) - i)
self.print_symbol(i)
print("\n", end = "")
i += 1
# Display the result of bottom half shell
i = 0
while (i < size) :
self.space(size - i)
self.print_symbol(size - i)
self.space(i + (int(size / 2)))
self.print_symbol(size - i)
print("\n", end = "")
i += 1
def main() :
obj = MyPattern()
obj.double_right_arrow(3)
obj.double_right_arrow(6)
obj.double_right_arrow(7)
if __name__ == "__main__":
main()
Output
Size : 3
> >
>> >>
>-> >->
>> >>
> >
Size : 6
> >
>> >>
>-> >->
>--> >-->
>---> >--->
>----> >---->
>---> >--->
>--> >-->
>-> >->
>> >>
> >
Size : 7
> >
>> >>
>-> >->
>--> >-->
>---> >--->
>----> >---->
>-----> >----->
>----> >---->
>---> >--->
>--> >-->
>-> >->
>> >>
> >
# Ruby Program
# Print Double Right Arrow Pattern
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
while (counter < size)
if (counter == 0 ||
counter + 1 == size)
print(">")
else
print("-")
end
counter += 1
end
end
# Display the double right arrow of given size
def double_right_arrow(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 + (size / 2) - i)
self.print_symbol(i)
print("\n")
i += 1
end
# Display the result of bottom half shell
i = 0
while (i < size)
self.space(size - i)
self.print_symbol(size - i)
self.space(i + (size / 2))
self.print_symbol(size - i)
print("\n")
i += 1
end
end
end
def main()
obj = MyPattern.new()
obj.double_right_arrow(3)
obj.double_right_arrow(6)
obj.double_right_arrow(7)
end
main()
Output
Size :3
> >
>> >>
>-> >->
>> >>
> >
Size :6
> >
>> >>
>-> >->
>--> >-->
>---> >--->
>----> >---->
>---> >--->
>--> >-->
>-> >->
>> >>
> >
Size :7
> >
>> >>
>-> >->
>--> >-->
>---> >--->
>----> >---->
>-----> >----->
>----> >---->
>---> >--->
>--> >-->
>-> >->
>> >>
> >
// Scala Program
// Print Double Right Arrow Pattern
class MyPattern {
/*Include Space of given size*/
def space(size: Int): Unit = {
var counter: Int = 0;
counter = 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 double right arrow of given size
def double_right_arrow(size: Int): Unit = {
print("\n Size : " + size + " \n");
var i: Int = 0;
//Display the result of top half shell
while (i < size) {
space(i);
print_symbol(i);
space(size + ((size / 2).toInt) - i);
print_symbol(i);
print("\n");
i += 1;
}
//Display the result of bottom half shell
i = 0;
while (i < size) {
space(size - i);
print_symbol(size - i);
space(i + ((size / 2).toInt));
print_symbol(size - i);
print("\n");
i += 1;
}
}
}
object Main {
def main(args: Array[String]): Unit = {
var obj: MyPattern = new MyPattern();
obj.double_right_arrow(3);
obj.double_right_arrow(6);
obj.double_right_arrow(7);
}
}
Output
Size : 3
> >
>> >>
>-> >->
>> >>
> >
Size : 6
> >
>> >>
>-> >->
>--> >-->
>---> >--->
>----> >---->
>---> >--->
>--> >-->
>-> >->
>> >>
> >
Size : 7
> >
>> >>
>-> >->
>--> >-->
>---> >--->
>----> >---->
>-----> >----->
>----> >---->
>---> >--->
>--> >-->
>-> >->
>> >>
> >
// Swift Program
// Print Double Right Arrow Pattern
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 double right arrow of given size
func double_right_arrow(_ size: Int) {
print("\n Size : ", size ," \n", terminator: "");
var i: Int = 0;
//Display the result of top half shell
while (i < size) {
self.space(i);
self.print_symbol(i);
self.space(size + (size / 2) - i);
self.print_symbol(i);
print("\n", terminator: "");
i += 1;
}
//Display the result of bottom half shell
i = 0;
while (i < size) {
self.space(size - i);
self.print_symbol(size - i);
self.space(i + (size / 2));
self.print_symbol(size - i);
print("\n", terminator: "");
i += 1;
}
}
}
func main() {
let obj: MyPattern = MyPattern();
obj.double_right_arrow(3);
obj.double_right_arrow(6);
obj.double_right_arrow(7);
}
main();
Output
Size : 3
> >
>> >>
>-> >->
>> >>
> >
Size : 6
> >
>> >>
>-> >->
>--> >-->
>---> >--->
>----> >---->
>---> >--->
>--> >-->
>-> >->
>> >>
> >
Size : 7
> >
>> >>
>-> >->
>--> >-->
>---> >--->
>----> >---->
>-----> >----->
>----> >---->
>---> >--->
>--> >-->
>-> >->
>> >>
> >
fn main() {
//Test Cases
double_right_arrow(3);
double_right_arrow(6);
double_right_arrow(7);
}
fn double_right_arrow(size: i32) {
print!("\n Size : {} \n", size);
let mut i: i32 = 0;
//Display the result of top half shell
while i < size {
space(i);
print_symbol(i);
space(size + (size / 2) - i);
print_symbol(i);
print!("\n");
i += 1;
}
i = 0;
//Display the result of bottom half shell
while i < size {
space(size - i);
print_symbol(size - i);
space(i + (size / 2));
print_symbol(size - i);
print!("\n");
i += 1;
}
}
fn print_symbol(size: i32) {
let mut counter: i32 = 0;
while counter < size {
if counter == 0 || counter + 1 == size {
print!(">");
}
else {
print!("-");
}
counter += 1;
}
}
fn space(size: i32) {
let mut counter: i32 = 0;
while counter < size {
//Add space
print!(" ");
counter += 1;
}
}
Output
Size : 3
> >
>> >>
>-> >->
>> >>
> >
Size : 6
> >
>> >>
>-> >->
>--> >-->
>---> >--->
>----> >---->
>---> >--->
>--> >-->
>-> >->
>> >>
> >
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