Print solid and hollow rhombus patterns

Here given code implementation process.

//  C program for
//  Print solid and hollow rhombus patterns
#include <stdio.h>
 // This is display empty space of given length
void includeSpace(int n)
{
	for (int i = 0; i < n; ++i)
	{
		printf(" ");
	}
}
void printRhombus(int height)
{
	printf("\nGiven height : %d \n", height);
	for (int i = 0; i < height; ++i)
	{
		includeSpace(height - i);
		// Solid rhombus
		for (int j = 0; j < height; ++j)
		{
			printf("*");
		}
		// separator
		includeSpace(5);
		// hollow rhombus
		for (int j = 0; j < height; ++j)
		{
			if (j == 0 || j + 1 == height || i == 0 || i + 1 == height)
			{
				printf("*");
			}
			else
			{
				printf(" ");
			}
		}
		printf("\n");
	}
}
int main(int argc, char
	const *argv[])
{
	// Test
	printRhombus(7);
	printRhombus(12);
	printRhombus(15);
	return 0;
}

Output

Given height : 7
       *******     *******
      *******     *     *
     *******     *     *
    *******     *     *
   *******     *     *
  *******     *     *
 *******     *******

Given height : 12
            ************     ************
           ************     *          *
          ************     *          *
         ************     *          *
        ************     *          *
       ************     *          *
      ************     *          *
     ************     *          *
    ************     *          *
   ************     *          *
  ************     *          *
 ************     ************

Given height : 15
               ***************     ***************
              ***************     *             *
             ***************     *             *
            ***************     *             *
           ***************     *             *
          ***************     *             *
         ***************     *             *
        ***************     *             *
       ***************     *             *
      ***************     *             *
     ***************     *             *
    ***************     *             *
   ***************     *             *
  ***************     *             *
 ***************     ***************
/*
    Java Program
    Print solid and hollow rhombus patterns
*/
public class Pattern
{
	// This is display empty space of given length
	public void includeSpace(int n)
	{
		for (int i = 0; i < n; ++i)
		{
			System.out.print(" ");
		}
	}
	public void printRhombus(int height)
	{
		System.out.print("\nGiven height : " + height + " \n");
		for (int i = 0; i < height; ++i)
		{
			includeSpace(height - i);
			// Solid rhombus
			for (int j = 0; j < height; ++j)
			{
				System.out.print("*");
			}
			// separator
			includeSpace(5);
			// hollow rhombus
			for (int j = 0; j < height; ++j)
			{
				if (j == 0 || j + 1 == height || i == 0 || i + 1 == height)
				{
					System.out.print("*");
				}
				else
				{
					System.out.print(" ");
				}
			}
			System.out.print("\n");
		}
	}
	public static void main(String[] args)
	{
		Pattern task = new Pattern();
		// Test
		task.printRhombus(7);
		task.printRhombus(12);
		task.printRhombus(15);
	}
}

Output

Given height : 7
       *******     *******
      *******     *     *
     *******     *     *
    *******     *     *
   *******     *     *
  *******     *     *
 *******     *******

Given height : 12
            ************     ************
           ************     *          *
          ************     *          *
         ************     *          *
        ************     *          *
       ************     *          *
      ************     *          *
     ************     *          *
    ************     *          *
   ************     *          *
  ************     *          *
 ************     ************

Given height : 15
               ***************     ***************
              ***************     *             *
             ***************     *             *
            ***************     *             *
           ***************     *             *
          ***************     *             *
         ***************     *             *
        ***************     *             *
       ***************     *             *
      ***************     *             *
     ***************     *             *
    ***************     *             *
   ***************     *             *
  ***************     *             *
 ***************     ***************
// Include header file
#include <iostream>
using namespace std;
/*
    C++ Program
    Print solid and hollow rhombus patterns
*/
class Pattern
{
	public:
		// This is display empty space of given length
		void includeSpace(int n)
		{
			for (int i = 0; i < n; ++i)
			{
				cout << " ";
			}
		}
	void printRhombus(int height)
	{
		cout << "\nGiven height : " << height << " \n";
		for (int i = 0; i < height; ++i)
		{
			this->includeSpace(height - i);
			// Solid rhombus
			for (int j = 0; j < height; ++j)
			{
				cout << "*";
			}
			// separator
			this->includeSpace(5);
			// hollow rhombus
			for (int j = 0; j < height; ++j)
			{
				if (j == 0 || j + 1 == height || 
                    i == 0 || i + 1 == height)
				{
					cout << "*";
				}
				else
				{
					cout << " ";
				}
			}
			cout << "\n";
		}
	}
};
int main()
{
	Pattern *task = new Pattern();
	// Test
	task->printRhombus(7);
	task->printRhombus(12);
	task->printRhombus(15);
	return 0;
}

Output

Given height : 7
       *******     *******
      *******     *     *
     *******     *     *
    *******     *     *
   *******     *     *
  *******     *     *
 *******     *******

Given height : 12
            ************     ************
           ************     *          *
          ************     *          *
         ************     *          *
        ************     *          *
       ************     *          *
      ************     *          *
     ************     *          *
    ************     *          *
   ************     *          *
  ************     *          *
 ************     ************

Given height : 15
               ***************     ***************
              ***************     *             *
             ***************     *             *
            ***************     *             *
           ***************     *             *
          ***************     *             *
         ***************     *             *
        ***************     *             *
       ***************     *             *
      ***************     *             *
     ***************     *             *
    ***************     *             *
   ***************     *             *
  ***************     *             *
 ***************     ***************
// Include namespace system
using System;
/*
    Csharp Program
    Print solid and hollow rhombus patterns
*/
public class Pattern
{
	// This is display empty space of given length
	public void includeSpace(int n)
	{
		for (int i = 0; i < n; ++i)
		{
			Console.Write(" ");
		}
	}
	public void printRhombus(int height)
	{
		Console.Write("\nGiven height : " + height + " \n");
		for (int i = 0; i < height; ++i)
		{
			this.includeSpace(height - i);
			// Solid rhombus
			for (int j = 0; j < height; ++j)
			{
				Console.Write("*");
			}
			// separator
			this.includeSpace(5);
			// hollow rhombus
			for (int j = 0; j < height; ++j)
			{
				if (j == 0 || j + 1 == height || 
                    i == 0 || i + 1 == height)
				{
					Console.Write("*");
				}
				else
				{
					Console.Write(" ");
				}
			}
			Console.Write("\n");
		}
	}
	public static void Main(String[] args)
	{
		Pattern task = new Pattern();
		// Test
		task.printRhombus(7);
		task.printRhombus(12);
		task.printRhombus(15);
	}
}

Output

Given height : 7
       *******     *******
      *******     *     *
     *******     *     *
    *******     *     *
   *******     *     *
  *******     *     *
 *******     *******

Given height : 12
            ************     ************
           ************     *          *
          ************     *          *
         ************     *          *
        ************     *          *
       ************     *          *
      ************     *          *
     ************     *          *
    ************     *          *
   ************     *          *
  ************     *          *
 ************     ************

Given height : 15
               ***************     ***************
              ***************     *             *
             ***************     *             *
            ***************     *             *
           ***************     *             *
          ***************     *             *
         ***************     *             *
        ***************     *             *
       ***************     *             *
      ***************     *             *
     ***************     *             *
    ***************     *             *
   ***************     *             *
  ***************     *             *
 ***************     ***************
package main
import "fmt"
/*
    Go Program
    Print solid and hollow rhombus patterns
*/
type Pattern struct {}
func getPattern() * Pattern {
	var me *Pattern = &Pattern {}
	return me
}
// This is display empty space of given length
func(this Pattern) includeSpace(n int) {
	for i := 0 ; i < n ; i++ {
		fmt.Print(" ")
	}
}
func(this Pattern) printRhombus(height int) {
	fmt.Print("\nGiven height : ", height, " \n")
	for i := 0 ; i < height ; i++ {
		this.includeSpace(height - i)
		// Solid rhombus
		for j := 0 ; j < height ; j++ {
			fmt.Print("*")
		}
		// separator
		this.includeSpace(5)
		// hollow rhombus
		for j := 0 ; j < height ; j++ {
			if j == 0 || j + 1 == height || 
			i == 0 || i + 1 == height {
				fmt.Print("*")
			} else {
				fmt.Print(" ")
			}
		}
		fmt.Print("\n")
	}
}
func main() {
	var task * Pattern = getPattern()
	// Test
	task.printRhombus(7)
	task.printRhombus(12)
	task.printRhombus(15)
}

Output

Given height : 7
       *******     *******
      *******     *     *
     *******     *     *
    *******     *     *
   *******     *     *
  *******     *     *
 *******     *******

Given height : 12
            ************     ************
           ************     *          *
          ************     *          *
         ************     *          *
        ************     *          *
       ************     *          *
      ************     *          *
     ************     *          *
    ************     *          *
   ************     *          *
  ************     *          *
 ************     ************

Given height : 15
               ***************     ***************
              ***************     *             *
             ***************     *             *
            ***************     *             *
           ***************     *             *
          ***************     *             *
         ***************     *             *
        ***************     *             *
       ***************     *             *
      ***************     *             *
     ***************     *             *
    ***************     *             *
   ***************     *             *
  ***************     *             *
 ***************     ***************
<?php
/*
    Php Program
    Print solid and hollow rhombus patterns
*/
class Pattern
{
	// This is display empty space of given length
	public	function includeSpace($n)
	{
		for ($i = 0; $i < $n; ++$i)
		{
			echo(" ");
		}
	}
	public	function printRhombus($height)
	{
		echo("\nGiven height : ".$height.
			" \n");
		for ($i = 0; $i < $height; ++$i)
		{
			$this->includeSpace($height - $i);
			// Solid rhombus
			for ($j = 0; $j < $height; ++$j)
			{
				echo("*");
			}
			// separator
			$this->includeSpace(5);
			// hollow rhombus
			for ($j = 0; $j < $height; ++$j)
			{
				if ($j == 0 || $j + 1 == $height ||
                    $i == 0 || $i + 1 == $height)
				{
					echo("*");
				}
				else
				{
					echo(" ");
				}
			}
			echo("\n");
		}
	}
}

function main()
{
	$task = new Pattern();
	// Test
	$task->printRhombus(7);
	$task->printRhombus(12);
	$task->printRhombus(15);
}
main();

Output

Given height : 7
       *******     *******
      *******     *     *
     *******     *     *
    *******     *     *
   *******     *     *
  *******     *     *
 *******     *******

Given height : 12
            ************     ************
           ************     *          *
          ************     *          *
         ************     *          *
        ************     *          *
       ************     *          *
      ************     *          *
     ************     *          *
    ************     *          *
   ************     *          *
  ************     *          *
 ************     ************

Given height : 15
               ***************     ***************
              ***************     *             *
             ***************     *             *
            ***************     *             *
           ***************     *             *
          ***************     *             *
         ***************     *             *
        ***************     *             *
       ***************     *             *
      ***************     *             *
     ***************     *             *
    ***************     *             *
   ***************     *             *
  ***************     *             *
 ***************     ***************
/*
    Node JS Program
    Print solid and hollow rhombus patterns
*/
class Pattern
{
	// This is display empty space of given length
	includeSpace(n)
	{
		for (var i = 0; i < n; ++i)
		{
			process.stdout.write(" ");
		}
	}
	printRhombus(height)
	{
		process.stdout.write("\nGiven height : " + height + " \n");
		for (var i = 0; i < height; ++i)
		{
			this.includeSpace(height - i);
			// Solid rhombus
			for (var j = 0; j < height; ++j)
			{
				process.stdout.write("*");
			}
			// separator
			this.includeSpace(5);
			// hollow rhombus
			for (var j = 0; j < height; ++j)
			{
				if (j == 0 || j + 1 == height || 
                    i == 0 || i + 1 == height)
				{
					process.stdout.write("*");
				}
				else
				{
					process.stdout.write(" ");
				}
			}
			process.stdout.write("\n");
		}
	}
}

function main()
{
	var task = new Pattern();
	// Test
	task.printRhombus(7);
	task.printRhombus(12);
	task.printRhombus(15);
}
main();

Output

Given height : 7
       *******     *******
      *******     *     *
     *******     *     *
    *******     *     *
   *******     *     *
  *******     *     *
 *******     *******

Given height : 12
            ************     ************
           ************     *          *
          ************     *          *
         ************     *          *
        ************     *          *
       ************     *          *
      ************     *          *
     ************     *          *
    ************     *          *
   ************     *          *
  ************     *          *
 ************     ************

Given height : 15
               ***************     ***************
              ***************     *             *
             ***************     *             *
            ***************     *             *
           ***************     *             *
          ***************     *             *
         ***************     *             *
        ***************     *             *
       ***************     *             *
      ***************     *             *
     ***************     *             *
    ***************     *             *
   ***************     *             *
  ***************     *             *
 ***************     ***************
#    Python 3 Program
#    Print solid and hollow rhombus patterns
class Pattern :
	#  This is display empty space of given length
	def includeSpace(self, n) :
		i = 0
		while (i < n) :
			print(" ", end = "")
			i += 1
		
	
	def printRhombus(self, height) :
		print("\nGiven height : ", height ," ")
		i = 0
		while (i < height) :
			self.includeSpace(height - i)
			j = 0
			#  Solid rhombus
			while (j < height) :
				print("*", end = "")
				j += 1
			
			#  separator
			self.includeSpace(5)
			j = 0
			#  hollow rhombus
			while (j < height) :
				if (j == 0 or j + 1 == height or 
                    i == 0 or i + 1 == height) :
					print("*", end = "")
				else :
					print(" ", end = "")
				
				j += 1
			
			print(end = "\n")
			i += 1
		
	

def main() :
	task = Pattern()
	#  Test
	task.printRhombus(7)
	task.printRhombus(12)
	task.printRhombus(15)

if __name__ == "__main__": main()

Output

Given height :  7
       *******     *******
      *******     *     *
     *******     *     *
    *******     *     *
   *******     *     *
  *******     *     *
 *******     *******

Given height :  12
            ************     ************
           ************     *          *
          ************     *          *
         ************     *          *
        ************     *          *
       ************     *          *
      ************     *          *
     ************     *          *
    ************     *          *
   ************     *          *
  ************     *          *
 ************     ************

Given height :  15
               ***************     ***************
              ***************     *             *
             ***************     *             *
            ***************     *             *
           ***************     *             *
          ***************     *             *
         ***************     *             *
        ***************     *             *
       ***************     *             *
      ***************     *             *
     ***************     *             *
    ***************     *             *
   ***************     *             *
  ***************     *             *
 ***************     ***************
#    Ruby Program
#    Print solid and hollow rhombus patterns
class Pattern 
	#  This is display empty space of given length
	def includeSpace(n) 
		i = 0
		while (i < n) 
			print(" ")
			i += 1
		end

	end

	def printRhombus(height) 
		print("\nGiven height : ", height ," \n")
		i = 0
		while (i < height) 
			self.includeSpace(height - i)
			j = 0
			#  Solid rhombus
			while (j < height) 
				print("*")
				j += 1
			end

			#  separator
			self.includeSpace(5)
			j = 0
			#  hollow rhombus
			while (j < height) 
				if (j == 0 || j + 1 == height || 
                    i == 0 || i + 1 == height) 
					print("*")
				else
 
					print(" ")
				end

				j += 1
			end

			print("\n")
			i += 1
		end

	end

end

def main() 
	task = Pattern.new()
	#  Test
	task.printRhombus(7)
	task.printRhombus(12)
	task.printRhombus(15)
end

main()

Output

Given height : 7 
       *******     *******
      *******     *     *
     *******     *     *
    *******     *     *
   *******     *     *
  *******     *     *
 *******     *******

Given height : 12 
            ************     ************
           ************     *          *
          ************     *          *
         ************     *          *
        ************     *          *
       ************     *          *
      ************     *          *
     ************     *          *
    ************     *          *
   ************     *          *
  ************     *          *
 ************     ************

Given height : 15 
               ***************     ***************
              ***************     *             *
             ***************     *             *
            ***************     *             *
           ***************     *             *
          ***************     *             *
         ***************     *             *
        ***************     *             *
       ***************     *             *
      ***************     *             *
     ***************     *             *
    ***************     *             *
   ***************     *             *
  ***************     *             *
 ***************     ***************
/*
    Scala Program
    Print solid and hollow rhombus patterns
*/
class Pattern()
{
	// This is display empty space of given length
	def includeSpace(n: Int): Unit = {
		var i: Int = 0;
		while (i < n)
		{
			print(" ");
			i += 1;
		}
	}
	def printRhombus(height: Int): Unit = {
		print("\nGiven height : " + height + " \n");
		var i: Int = 0;
		while (i < height)
		{
			includeSpace(height - i);
			var j: Int = 0;
			// Solid rhombus
			while (j < height)
			{
				print("*");
				j += 1;
			}
			// separator
			includeSpace(5);
			j = 0;
			// hollow rhombus
			while (j < height)
			{
				if (j == 0 || j + 1 == height || 
                    i == 0 || i + 1 == height)
				{
					print("*");
				}
				else
				{
					print(" ");
				}
				j += 1;
			}
			print("\n");
			i += 1;
		}
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: Pattern = new Pattern();
		// Test
		task.printRhombus(7);
		task.printRhombus(12);
		task.printRhombus(15);
	}
}

Output

Given height : 7
       *******     *******
      *******     *     *
     *******     *     *
    *******     *     *
   *******     *     *
  *******     *     *
 *******     *******

Given height : 12
            ************     ************
           ************     *          *
          ************     *          *
         ************     *          *
        ************     *          *
       ************     *          *
      ************     *          *
     ************     *          *
    ************     *          *
   ************     *          *
  ************     *          *
 ************     ************

Given height : 15
               ***************     ***************
              ***************     *             *
             ***************     *             *
            ***************     *             *
           ***************     *             *
          ***************     *             *
         ***************     *             *
        ***************     *             *
       ***************     *             *
      ***************     *             *
     ***************     *             *
    ***************     *             *
   ***************     *             *
  ***************     *             *
 ***************     ***************
/*
    Swift 4 Program
    Print solid and hollow rhombus patterns
*/
class Pattern
{
	// This is display empty space of given length
	func includeSpace(_ n: Int)
	{
		var i: Int = 0;
		while (i < n)
		{
			print(" ", terminator: "");
			i += 1;
		}
	}
	func printRhombus(_ height: Int)
	{
		print("\nGiven height : ", height ," ");
		var i: Int = 0;
		while (i < height)
		{
			self.includeSpace(height - i);
			var j: Int = 0;
			// Solid rhombus
			while (j < height)
			{
				print("*", terminator: "");
				j += 1;
			}
			// separator
			self.includeSpace(5);
			j = 0;
			// hollow rhombus
			while (j < height)
			{
				if (j == 0 || j + 1 == height || i == 0 || i + 1 == height)
				{
					print("*", terminator: "");
				}
				else
				{
					print(" ", terminator: "");
				}
				j += 1;
			}
			print(terminator: "\n");
			i += 1;
		}
	}
}
func main()
{
	let task: Pattern = Pattern();
	// Test
	task.printRhombus(7);
	task.printRhombus(12);
	task.printRhombus(15);
}
main();

Output

Given height :  7
       *******     *******
      *******     *     *
     *******     *     *
    *******     *     *
   *******     *     *
  *******     *     *
 *******     *******

Given height :  12
            ************     ************
           ************     *          *
          ************     *          *
         ************     *          *
        ************     *          *
       ************     *          *
      ************     *          *
     ************     *          *
    ************     *          *
   ************     *          *
  ************     *          *
 ************     ************

Given height :  15
               ***************     ***************
              ***************     *             *
             ***************     *             *
            ***************     *             *
           ***************     *             *
          ***************     *             *
         ***************     *             *
        ***************     *             *
       ***************     *             *
      ***************     *             *
     ***************     *             *
    ***************     *             *
   ***************     *             *
  ***************     *             *
 ***************     ***************
/*
    Kotlin Program
    Print solid and hollow rhombus patterns
*/
class Pattern
{
	// This is display empty space of given length
	fun includeSpace(n: Int): Unit
	{
		var i: Int = 0;
		while (i < n)
		{
			print(" ");
			i += 1;
		}
	}
	fun printRhombus(height: Int): Unit
	{
		print("\nGiven height : " + height + " \n");
		var i: Int = 0;
		while (i < height)
		{
			this.includeSpace(height - i);
			var j: Int = 0;
			// Solid rhombus
			while (j < height)
			{
				print("*");
				j += 1;
			}
			// separator
			this.includeSpace(5);
			j = 0;
			// hollow rhombus
			while (j < height)
			{
				if (j == 0 || j + 1 == height || 
                    i == 0 || i + 1 == height)
				{
					print("*");
				}
				else
				{
					print(" ");
				}
				j += 1;
			}
			print("\n");
			i += 1;
		}
	}
}
fun main(args: Array < String > ): Unit
{
	val task: Pattern = Pattern();
	// Test
	task.printRhombus(7);
	task.printRhombus(12);
	task.printRhombus(15);
}

Output

Given height : 7
       *******     *******
      *******     *     *
     *******     *     *
    *******     *     *
   *******     *     *
  *******     *     *
 *******     *******

Given height : 12
            ************     ************
           ************     *          *
          ************     *          *
         ************     *          *
        ************     *          *
       ************     *          *
      ************     *          *
     ************     *          *
    ************     *          *
   ************     *          *
  ************     *          *
 ************     ************

Given height : 15
               ***************     ***************
              ***************     *             *
             ***************     *             *
            ***************     *             *
           ***************     *             *
          ***************     *             *
         ***************     *             *
        ***************     *             *
       ***************     *             *
      ***************     *             *
     ***************     *             *
    ***************     *             *
   ***************     *             *
  ***************     *             *
 ***************     ***************


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