Display Kite Pattern

Here given code implementation process.

//C Program 
//Display Kite 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(" ");
  }
}
/*Print value of given size*/
void print_pattern(int size) {

  int counter = 0;

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

    if (counter == 0) {

      /*Print symbol*/
      printf("/");

    } else if (counter == size - 1) {
      /*Print symbol*/
      printf("\\");
    } else {
      /*Add intermediate values*/
      if(counter==size/2 -1)
      {
        printf("|");
        counter++;
      }
      else
      {
        printf("-");
      }
    }
  }
}
//Display kite pattern
void kite_pattern(int size) {

  
  printf("\n Size : %d \n\n", size);
  int i = 0, j = 0;
  //Display upper half portion
  for (i = 1; i < size; i++) {

    space(size - i  );
    if(i==1)
    {
      printf("^\n");
      continue;
    }
    print_pattern(i *2);

    printf("\n");
  }
  //Display bottom half portion
  for (i = 0; i < size; i++) {
    
    if(i==size-1)
    {
      //Display bottom of kite
      space(i-1);
      printf("/-\\\n");
      space(i-1);
      printf("~~~");
    }
    else
    {
      space(i);
      print_pattern((size - i) *2);
    }
    printf("\n");
  }

}


int main() {
  //Test Cases
  kite_pattern(3);
  kite_pattern(5);
  kite_pattern(7);
  return 0;
}

Output

 Size : 3

  ^
 /|\
/-|-\
 /|\
 /-\
 ~~~

 Size : 5

    ^
   /|\
  /-|-\
 /--|--\
/---|---\
 /--|--\
  /-|-\
   /|\
   /-\
   ~~~

 Size : 7

      ^
     /|\
    /-|-\
   /--|--\
  /---|---\
 /----|----\
/-----|-----\
 /----|----\
  /---|---\
   /--|--\
    /-|-\
     /|\
     /-\
     ~~~
/*
  C++ Program
  Display Kite 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 << " ";
      }
    }
	/*Print value of given size*/
	void print_pattern(int size) {
		int counter = 0;
		for (counter = 0; counter < size; counter++) {
			if (counter == 0) {
				/*Print symbol*/

				cout << "/";
			} else
			if (counter == size - 1) {
				/*Print symbol*/

				cout << "\\";
			} else {
				/*Add intermediate values*/

				if (counter == size / 2 - 1) {
					cout << "|";
					counter++;
				} else {
					cout << "-";
				}
			}
		}
	}
	//Display kite pattern
	void kite_pattern(int size) {
		if (size < 3) {
			return;
		}
		cout << "\n Size : " << size << " \n\n";
		int i = 0, j = 0;
		//Display upper half portion

		for (i = 1; i < size; i++) {
			this->space(size - i);
			if (i == 1) {
				cout << "^";
			} else {
				this->print_pattern(i *2);
			}
			cout << "\n";
		}
		//Display bottom half portion
		for (i = 0; i < size; i++) {
			if (i == size - 1) {
				//Display bottom of kite
				this->space(i - 1);
				cout << "/-\\\n";
				this->space(i - 1);
				cout << "~~~";
			} else {
				this->space(i);
				this->print_pattern((size - i) *2);
			}
			cout << "\n";
		}
	}
};
int main() {
	MyPattern obj =  MyPattern();
	//Test Cases
	obj.kite_pattern(3);
	obj.kite_pattern(5);
	obj.kite_pattern(7);
	return 0;
}

Output

 Size : 3

  ^
 /|\
/-|-\
 /|\
 /-\
 ~~~

 Size : 5

    ^
   /|\
  /-|-\
 /--|--\
/---|---\
 /--|--\
  /-|-\
   /|\
   /-\
   ~~~

 Size : 7

      ^
     /|\
    /-|-\
   /--|--\
  /---|---\
 /----|----\
/-----|-----\
 /----|----\
  /---|---\
   /--|--\
    /-|-\
     /|\
     /-\
     ~~~
/*
  Java Program
  Display Kite 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(" ");
    }
  }
  /*Print value of given size*/
  public void print_pattern(int size) {

    int counter = 0;

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

      if (counter == 0) {

        /*Print symbol*/
        System.out.print("/");

      } else if (counter == size - 1) {
        /*Print symbol*/
        System.out.print("\\");
      } else {
        /*Add intermediate values*/
        if(counter==size/2 -1)
        {
          System.out.print("|");
          counter++;
        }
        else
        {
          System.out.print("-");
        }
      }
    }
  }
  //Display kite pattern
  public void kite_pattern(int size) {

    if(size<3)
    {
      return;
    }
    System.out.print("\n Size : "+size+" \n\n");
    int i = 0;
    //Display upper half portion
    for (i = 1; i < size; i++) {
      
      space(size - i  );
      if(i==1)
      {
        System.out.print("^");
        
      }
      else
      {
        print_pattern(i *2);
      }
      

      System.out.print("\n");
    }
    //Display bottom half portion
    for (i = 0; i < size; i++) {
      
      if(i==size-1)
      {
        //Display bottom of kite
        space(i-1);
        System.out.print("/-\\\n");
        space(i-1);
        System.out.print("~~~");
      }
      else
      {
        space(i);
        print_pattern((size - i) *2);
      }
      System.out.print("\n");
    }

  }

  public static void main(String[] args) {

    MyPattern obj = new MyPattern();

    
    //Test Cases
    obj.kite_pattern(3);
    obj.kite_pattern(5);
    obj.kite_pattern(7);
  }
}

Output

 Size : 3

  ^
 /|\
/-|-\
 /|\
 /-\
 ~~~

 Size : 5

    ^
   /|\
  /-|-\
 /--|--\
/---|---\
 /--|--\
  /-|-\
   /|\
   /-\
   ~~~

 Size : 7

      ^
     /|\
    /-|-\
   /--|--\
  /---|---\
 /----|----\
/-----|-----\
 /----|----\
  /---|---\
   /--|--\
    /-|-\
     /|\
     /-\
     ~~~
/*
  C# Program
  Display Kite 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(" ");
		}
	}
	/*Print value of given size*/
	public void print_pattern(int size) {
		int counter = 0;
		for (counter = 0; counter < size; counter++) {
			if (counter == 0) {
				Console.Write("/");
			} else
			if (counter == size - 1) {
				Console.Write("\\");
			} else {
				/*Add intermediate values*/

				if (counter == size / 2 - 1) {
					Console.Write("|");
					counter++;
				} else {
					Console.Write("-");
				}
			}
		}
	}
	//Display kite pattern
	public void kite_pattern(int size) {
		if (size < 3) {
			return;
		}
		Console.Write("\n Size : " + size + " \n\n");
		int i = 0;
		//Display upper half portion

		for (i = 1; i < size; i++) {
			space(size - i);
			if (i == 1) {
				Console.Write("^");
			} else {
				print_pattern(i * 2);
			}
			Console.Write("\n");
		}
		//Display bottom half portion

		for (i = 0; i < size; i++) {
			if (i == size - 1) {
				space(i - 1);
				Console.Write("/-\\\n");
				space(i - 1);
				Console.Write("~~~");
			} else {
				space(i);
				print_pattern((size - i) * 2);
			}
			Console.Write("\n");
		}
	}
	public static void Main(String[] args) {
		MyPattern obj = new MyPattern();
		obj.kite_pattern(3);
		obj.kite_pattern(5);
		obj.kite_pattern(7);
	}
}

Output

 Size : 3

  ^
 /|\
/-|-\
 /|\
 /-\
 ~~~

 Size : 5

    ^
   /|\
  /-|-\
 /--|--\
/---|---\
 /--|--\
  /-|-\
   /|\
   /-\
   ~~~

 Size : 7

      ^
     /|\
    /-|-\
   /--|--\
  /---|---\
 /----|----\
/-----|-----\
 /----|----\
  /---|---\
   /--|--\
    /-|-\
     /|\
     /-\
     ~~~
<?php
/*
  Php Program
  Display Kite Pattern
*/
class MyPattern {
	/*include Space of given size*/

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

			echo(" ");
		}
	}
	/*Print value of given size*/

	public 	function print_pattern($size) {
		$counter = 0;
		for ($counter = 0; $counter < $size; $counter++) {
			if ($counter == 0) {
				/*Print symbol*/

				echo("/");
			} else
			if ($counter == $size - 1) {
				/*Print symbol*/

				echo("\\");
			} else {
				/*Add intermediate values*/

				if ($counter == intval($size / 2) - 1) {
					echo("|");
					$counter++;
				} else {
					echo("-");
				}
			}
		}
	}
	//Display kite pattern

	public 	function kite_pattern($size) {
		if ($size < 3) {
			return;
		}
		echo("\n Size : ". $size ." \n\n");
		$i = 0;
		//Display upper half portion

		for ($i = 1; $i < $size; $i++) {
			$this->space($size - $i);
			if ($i == 1) {
				echo("^");
			} else {
				$this->print_pattern($i *2);
			}
			echo("\n");
		}
		//Display bottom half portion

		for ($i = 0; $i < $size; $i++) {
			if ($i == $size - 1) {
				//Display bottom of kite
				$this->space($i - 1);
				echo("/-\\\n");
				$this->space($i - 1);
				echo("~~~");
			} else {
				$this->space($i);
				$this->print_pattern(($size - $i) *2);
			}
			echo("\n");
		}
	}
}

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

}
main();

Output

 Size : 3

  ^
 /|\
/-|-\
 /|\
 /-\
 ~~~

 Size : 5

    ^
   /|\
  /-|-\
 /--|--\
/---|---\
 /--|--\
  /-|-\
   /|\
   /-\
   ~~~

 Size : 7

      ^
     /|\
    /-|-\
   /--|--\
  /---|---\
 /----|----\
/-----|-----\
 /----|----\
  /---|---\
   /--|--\
    /-|-\
     /|\
     /-\
     ~~~
/*
  Node Js Program
  Display Kite Pattern
*/
class MyPattern {
	/*include Space of given size*/
	space(size) {
		var counter = 0;
		for (counter = 0; counter < size; counter++) {
			//Add space

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

	/*Print value of given size*/
	print_pattern(size) {
		var counter = 0;
		for (counter = 0; counter < size; counter++) {
			if (counter == 0) {
				/*Print symbol*/

				process.stdout.write("/");
			} else
			if (counter == size - 1) {
				/*Print symbol*/

				process.stdout.write("\\");
			} else {
				/*Add intermediate values*/

				if (counter == parseInt(size / 2) - 1) {
					process.stdout.write("|");
					counter++;
				} else {
					process.stdout.write("-");
				}
			}
		}
	}

	//Display kite pattern
	kite_pattern(size) {
		if (size < 3) {
			return;
		}

		process.stdout.write("\n Size : " + size + " \n\n");
		var i = 0;
		//Display upper half portion

		for (i = 1; i < size; i++) {
			this.space(size - i);
			if (i == 1) {
				process.stdout.write("^");
			} else {
				this.print_pattern(i *2);
			}

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

		//Display bottom half portion

		for (i = 0; i < size; i++) {
			if (i == size - 1) {
				//Display bottom of kite
				this.space(i - 1);
				process.stdout.write("/-\\\n");
				this.space(i - 1);
				process.stdout.write("~~~");
			} else {
				this.space(i);
				this.print_pattern((size - i) *2);
			}

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

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

main();

Output

 Size : 3

  ^
 /|\
/-|-\
 /|\
 /-\
 ~~~

 Size : 5

    ^
   /|\
  /-|-\
 /--|--\
/---|---\
 /--|--\
  /-|-\
   /|\
   /-\
   ~~~

 Size : 7

      ^
     /|\
    /-|-\
   /--|--\
  /---|---\
 /----|----\
/-----|-----\
 /----|----\
  /---|---\
   /--|--\
    /-|-\
     /|\
     /-\
     ~~~
#   Python 3 Program
#   Display Kite Pattern

class MyPattern :
	# include Space of given size 
	def space(self, size) :
		counter = 0
		counter = 0
		while (counter < size) :
			print(" ", end = "")
			counter += 1
		
	
	# Print value of given size
	def print_pattern(self, size) :
		counter = 0
		counter = 0
		while (counter < size) :
			if (counter == 0) :
				print("/", end = "")
			elif (counter == size - 1) :
				print("\\", end = "")
			else :
				# Add intermediate values
			
				if (counter == int(size / 2) - 1) :
					print("|", end = "")
					counter += 1
				else :
					print("-", end = "")
				
			
			counter += 1
		
	
	# Display kite pattern
	def kite_pattern(self, size) :
		if (size < 3) :
			return
		
		print("\n Size : ", size ," \n\n", end = "")
		i = 0
		# Display upper half portion
		i = 1
		while (i < size) :
			self.space(size - i)
			if (i == 1) :
				print("^", end = "")
			else :
				self.print_pattern(i * 2)
			
			print("\n", end = "")
			i += 1
		
		# Display bottom half portion
		i = 0
		while (i < size) :
			if (i == size - 1) :
				self.space(i - 1)
				print("/-\\\n", end = "")
				self.space(i - 1)
				print("~~~", end = "")
			else :
				self.space(i)
				self.print_pattern((size - i) * 2)
			
			print("\n", end = "")
			i += 1
		
	

def main() :
	obj = MyPattern()
	obj.kite_pattern(3)
	obj.kite_pattern(5)
	obj.kite_pattern(7)


if __name__ == "__main__":
	main()

Output

 Size :  3

  ^
 /|\
/-|-\
 /|\
 /-\
 ~~~

 Size :  5

    ^
   /|\
  /-|-\
 /--|--\
/---|---\
 /--|--\
  /-|-\
   /|\
   /-\
   ~~~

 Size :  7

      ^
     /|\
    /-|-\
   /--|--\
  /---|---\
 /----|----\
/-----|-----\
 /----|----\
  /---|---\
   /--|--\
    /-|-\
     /|\
     /-\
     ~~~
#   Ruby Program
#   Display Kite Pattern

class MyPattern 
	# include Space of given size
	def space(size) 
		counter = 0
		counter = 0
		while (counter < size) 
			print(" ")
			counter += 1
		end
	end
	# Print value of given size
	def print_pattern(size) 
		counter = 0
		counter = 0
		while (counter < size) 
			if (counter == 0) 
				print("/")
			elsif (counter == size - 1) 
				print("\\")
			else 
				# Add intermediate values
			
				if (counter == size / 2 - 1) 
					print("|")
					counter += 1
				else 
					print("-")
				end
			end
			counter += 1
		end
	end
	 # Display kite pattern
	def kite_pattern(size) 
		if (size < 3) 
			return
		end
		print("\n Size  :", size ," \n\n")
		i = 0
		 # Display upper half portion
		i = 1
		while (i < size) 
			self.space(size - i)
			if (i == 1) 
				print("^")
			else 
				self.print_pattern(i * 2)
			end
			print("\n")
			i += 1
		end
		 # Display bottom half portion
		i = 0
		while (i < size) 
			if (i == size - 1) 
				self.space(i - 1)
				print("/-\\\n")
				self.space(i - 1)
				print("~~~")
			else 
				self.space(i)
				self.print_pattern((size - i) * 2)
			end
			print("\n")
			i += 1
		end
	end
end
def main() 
	obj = MyPattern.new()
	obj.kite_pattern(3)
	obj.kite_pattern(5)
	obj.kite_pattern(7)
end
main()

Output

 Size  :3 

  ^
 /|\
/-|-\
 /|\
 /-\
 ~~~

 Size  :5 

    ^
   /|\
  /-|-\
 /--|--\
/---|---\
 /--|--\
  /-|-\
   /|\
   /-\
   ~~~

 Size  :7 

      ^
     /|\
    /-|-\
   /--|--\
  /---|---\
 /----|----\
/-----|-----\
 /----|----\
  /---|---\
   /--|--\
    /-|-\
     /|\
     /-\
     ~~~
/*
  Scala Program
  Display Kite 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;
		}
	}
	/*Print value of given size*/
	def print_pattern(size: Int): Unit = {
		var counter: Int = 0;
		counter = 0;
		while (counter < size) {
			if (counter == 0) {
				print("/");
			} else
			if (counter == size - 1) {
				print("\\");
			} else {
				/*Add intermediate values*/

				if (counter == (size / 2).toInt - 1) {
					print("|");
					counter += 1;
				} else {
					print("-");
				}
			}
			counter += 1;
		}
	}
	//Display kite pattern
	def kite_pattern(size: Int): Unit = {
		if (size < 3) {
			return;
		}
		print("\n Size : " + size + " \n\n");
		var i: Int = 0;

		//Display upper half portion
		i = 1;
		while (i < size) {
			this.space(size - i);

			if (i == 1) {
				print("^");
			} else {
				this.print_pattern(i * 2);
			}
			print("\n");
			i += 1;
		}
		//Display bottom half portion
		i = 0;
		while (i < size) {
			if (i == size - 1) {
				this.space(i - 1);
				print("/-\\\n");
				this.space(i - 1);
				print("~~~");
			} else {
				this.space(i);
				this.print_pattern((size - i) * 2);
			}
			print("\n");
			i += 1;
		}
	}
}
object Main {
	def main(args: Array[String]): Unit = {
		val obj: MyPattern = new MyPattern();
		obj.kite_pattern(3);
		obj.kite_pattern(5);
		obj.kite_pattern(7);
	}
}

Output

 Size : 3

  ^
 /|\
/-|-\
 /|\
 /-\
 ~~~

 Size : 5

    ^
   /|\
  /-|-\
 /--|--\
/---|---\
 /--|--\
  /-|-\
   /|\
   /-\
   ~~~

 Size : 7

      ^
     /|\
    /-|-\
   /--|--\
  /---|---\
 /----|----\
/-----|-----\
 /----|----\
  /---|---\
   /--|--\
    /-|-\
     /|\
     /-\
     ~~~
/*
  Swift Program
  Display Kite Pattern
*/
class MyPattern {
	/*include Space of given size*/
	func space(_ size: Int) {
		var counter = 0;
		counter = 0;
		while (counter < size) {
			print(" ", terminator: "");
			counter += 1;
		}
	}
	/*Print value of given size*/
	func print_pattern(_ size: Int) {
		var counter = 0;
		counter = 0;
		while (counter < size) {
			if (counter == 0) {
				print("/", terminator: "");
			} else
			if (counter == size - 1) {
				print("\\", terminator: "");
			} else {
				/*Add intermediate values*/

				if (counter == size / 2 - 1) {
					print("|", terminator: "");
					counter += 1;
				} else {
					print("-", terminator: "");
				}
			}
			counter += 1;
		}
	}
	//Display kite pattern
	func kite_pattern(_ size: Int) {
		if (size < 3) {
			return;
		}
		print("\n Size : ", size ," \n\n", terminator: "");
		var i = 0;
		//Display upper half portion
		i = 1;
		while (i < size) {
			self.space(size - i);
			if (i == 1) {
				print("^", terminator: "");
			} else {
				self.print_pattern(i * 2);
			}
			print("\n", terminator: "");
			i += 1;
		}
		//Display bottom half portion
		i = 0;
		while (i < size) {
			if (i == size - 1) {
				self.space(i - 1);
				print("/-\\\n", terminator: "");
				self.space(i - 1);
				print("~~~", terminator: "");
			} else {
				self.space(i);
				self.print_pattern((size - i) * 2);
			}
			print("\n", terminator: "");
			i += 1;
		}
	}
}
func main() {
	let obj = MyPattern();
	obj.kite_pattern(3);
	obj.kite_pattern(5);
	obj.kite_pattern(7);
}
main();

Output

 Size :  3

  ^
 /|\
/-|-\
 /|\
 /-\
 ~~~

 Size :  5

    ^
   /|\
  /-|-\
 /--|--\
/---|---\
 /--|--\
  /-|-\
   /|\
   /-\
   ~~~

 Size :  7

      ^
     /|\
    /-|-\
   /--|--\
  /---|---\
 /----|----\
/-----|-----\
 /----|----\
  /---|---\
   /--|--\
    /-|-\
     /|\
     /-\
     ~~~


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved