Mountain Sequence Pattern

Here given code implementation process.

// C program for
// Mountain Sequence Pattern
#include <stdio.h>

// Include n space
void includeSpace(int n)
{
	for (int i = 0; i < n; ++i)
	{
		printf(" ");
	}
}
// Include n star with space
void includeStar(int n)
{
	for (int i = 0; i < n; ++i)
	{
		printf("* ");
	}
}
void mountainSequence(int n)
{
	if (n <= 0)
	{
		return;
	}
	int height = 5;
	printf("\n Given Size : %d \n", n);
	// Outer loop is executing in through by mountain height
	for (int i = 0; i <= height; ++i)
	{
		// Inner loop is executing in through by 0..n
		for (int j = 0; j < n; ++j)
		{
			// Include initial space
			includeSpace(height - i);
			// Display the mountain element
			includeStar(i);
			// Include end space
			includeSpace(height - i);
		}
		// Include new line
		printf("\n");
	}
}
int main(int argc, char const *argv[])
{
	// Test Cases
	mountainSequence(1);
	mountainSequence(2);
	mountainSequence(4);
	mountainSequence(3);
	return 0;
}

input

 Given Size : 1

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

 Given Size : 2

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

 Given Size : 4

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

 Given Size : 3

    *         *         *
   * *       * *       * *
  * * *     * * *     * * *
 * * * *   * * * *   * * * *
* * * * * * * * * * * * * * *
/*
    Java Program
    Mountain Sequence Pattern
*/
public class MountainPattern
{
	// Include n space
	public void includeSpace(int n)
	{
		for (int i = 0; i < n; ++i)
		{
			System.out.print(" ");
		}
	}
	// Include n star with space
	public void includeStar(int n)
	{
		for (int i = 0; i < n; ++i)
		{
			System.out.print("* ");
		}
	}
	public void mountainSequence(int n)
	{
		if (n <= 0)
		{
			return;
		}
		int height = 5;
		System.out.println("\n Given Size : " + n);
		// Outer loop is executing in through by mountain height
		for (int i = 0; i <= height; ++i)
		{
			// Inner loop is executing in through by 0..n
			for (int j = 0; j < n; ++j)
			{
				// Include initial space
				includeSpace(height - i);
				// Display the mountain element
				includeStar(i);
				// Include end space
				includeSpace(height - i);
			}
			// Include new line
			System.out.print("\n");
		}
	}
	public static void main(String[] args)
	{
		MountainPattern task = new MountainPattern();
		// Test Cases
		task.mountainSequence(1);
		task.mountainSequence(2);
		task.mountainSequence(4);
		task.mountainSequence(3);
	}
}

input

 Given Size : 1

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

 Given Size : 2

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

 Given Size : 4

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

 Given Size : 3

    *         *         *
   * *       * *       * *
  * * *     * * *     * * *
 * * * *   * * * *   * * * *
* * * * * * * * * * * * * * *
// Include header file
#include <iostream>

using namespace std;
/*
    C++ Program
    Mountain Sequence Pattern
*/
class MountainPattern
{
	public:
		// Include n space
		void includeSpace(int n)
		{
			for (int i = 0; i < n; ++i)
			{
				cout << " ";
			}
		}
	// Include n star with space
	void includeStar(int n)
	{
		for (int i = 0; i < n; ++i)
		{
			cout << "* ";
		}
	}
	void mountainSequence(int n)
	{
		if (n <= 0)
		{
			return;
		}
		int height = 5;
		cout << "\n Given Size : " << n << endl;
		// Outer loop is executing in through by mountain height
		for (int i = 0; i <= height; ++i)
		{
			// Inner loop is executing in through by 0..n
			for (int j = 0; j < n; ++j)
			{
				// Include initial space
				this->includeSpace(height - i);
				// Display the mountain element
				this->includeStar(i);
				// Include end space
				this->includeSpace(height - i);
			}
			// Include new line
			cout << "\n";
		}
	}
};
int main()
{
	MountainPattern *task = new MountainPattern();
	// Test Cases
	task->mountainSequence(1);
	task->mountainSequence(2);
	task->mountainSequence(4);
	task->mountainSequence(3);
	return 0;
}

input

 Given Size : 1

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

 Given Size : 2

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

 Given Size : 4

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

 Given Size : 3

    *         *         *
   * *       * *       * *
  * * *     * * *     * * *
 * * * *   * * * *   * * * *
* * * * * * * * * * * * * * *
// Include namespace system
using System;
/*
    Csharp Program
    Mountain Sequence Pattern
*/
public class MountainPattern
{
	// Include n space
	public void includeSpace(int n)
	{
		for (int i = 0; i < n; ++i)
		{
			Console.Write(" ");
		}
	}
	// Include n star with space
	public void includeStar(int n)
	{
		for (int i = 0; i < n; ++i)
		{
			Console.Write("* ");
		}
	}
	public void mountainSequence(int n)
	{
		if (n <= 0)
		{
			return;
		}
		int height = 5;
		Console.WriteLine("\n Given Size : " + n);
		// Outer loop is executing in through by mountain height
		for (int i = 0; i <= height; ++i)
		{
			// Inner loop is executing in through by 0..n
			for (int j = 0; j < n; ++j)
			{
				// Include initial space
				this.includeSpace(height - i);
				// Display the mountain element
				this.includeStar(i);
				// Include end space
				this.includeSpace(height - i);
			}
			// Include new line
			Console.Write("\n");
		}
	}
	public static void Main(String[] args)
	{
		MountainPattern task = new MountainPattern();
		// Test Cases
		task.mountainSequence(1);
		task.mountainSequence(2);
		task.mountainSequence(4);
		task.mountainSequence(3);
	}
}

input

 Given Size : 1

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

 Given Size : 2

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

 Given Size : 4

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

 Given Size : 3

    *         *         *
   * *       * *       * *
  * * *     * * *     * * *
 * * * *   * * * *   * * * *
* * * * * * * * * * * * * * *
<?php
/*
    Php Program
    Mountain Sequence Pattern
*/
class MountainPattern
{
	// Include n space
	public	function includeSpace($n)
	{
		for ($i = 0; $i < $n; ++$i)
		{
			echo(" ");
		}
	}
	// Include n star with space
	public	function includeStar($n)
	{
		for ($i = 0; $i < $n; ++$i)
		{
			echo("* ");
		}
	}
	public	function mountainSequence($n)
	{
		if ($n <= 0)
		{
			return;
		}
		$height = 5;
		echo("\n Given Size : ".$n."\n");
		// Outer loop is executing in through by mountain height
		for ($i = 0; $i <= $height; ++$i)
		{
			// Inner loop is executing in through by 0..n
			for ($j = 0; $j < $n; ++$j)
			{
				// Include initial space
				$this->includeSpace($height - $i);
				// Display the mountain element
				$this->includeStar($i);
				// Include end space
				$this->includeSpace($height - $i);
			}
			// Include new line
			echo("\n");
		}
	}
}

function main()
{
	$task = new MountainPattern();
	// Test Cases
	$task->mountainSequence(1);
	$task->mountainSequence(2);
	$task->mountainSequence(4);
	$task->mountainSequence(3);
}
main();

input

 Given Size : 1

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

 Given Size : 2

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

 Given Size : 4

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

 Given Size : 3

    *         *         *
   * *       * *       * *
  * * *     * * *     * * *
 * * * *   * * * *   * * * *
* * * * * * * * * * * * * * *
/*
    Node JS Program
    Mountain Sequence Pattern
*/
class MountainPattern
{
	// Include n space
	includeSpace(n)
	{
		for (var i = 0; i < n; ++i)
		{
			process.stdout.write(" ");
		}
	}
	// Include n star with space
	includeStar(n)
	{
		for (var i = 0; i < n; ++i)
		{
			process.stdout.write("* ");
		}
	}
	mountainSequence(n)
	{
		if (n <= 0)
		{
			return;
		}
		var height = 5;
		console.log("\n Given Size : " + n);
		// Outer loop is executing in through by mountain height
		for (var i = 0; i <= height; ++i)
		{
			// Inner loop is executing in through by 0..n
			for (var j = 0; j < n; ++j)
			{
				// Include initial space
				this.includeSpace(height - i);
				// Display the mountain element
				this.includeStar(i);
				// Include end space
				this.includeSpace(height - i);
			}
			// Include new line
			process.stdout.write("\n");
		}
	}
}

function main()
{
	var task = new MountainPattern();
	// Test Cases
	task.mountainSequence(1);
	task.mountainSequence(2);
	task.mountainSequence(4);
	task.mountainSequence(3);
}
main();

input

 Given Size : 1

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

 Given Size : 2

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

 Given Size : 4

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

 Given Size : 3

    *         *         *
   * *       * *       * *
  * * *     * * *     * * *
 * * * *   * * * *   * * * *
* * * * * * * * * * * * * * *
#    Python 3 Program
#    Mountain Sequence Pattern
class MountainPattern :
	#  Include n space
	def includeSpace(self, n) :
		i = 0
		while (i < n) :
			print(" ", end = "")
			i += 1
		
	
	#  Include n star with space
	def includeStar(self, n) :
		i = 0
		while (i < n) :
			print("* ", end = "")
			i += 1
		
	
	def mountainSequence(self, n) :
		if (n <= 0) :
			return
		
		height = 5
		print("\n Given Size : ", n)
		#  Outer loop is executing in through by mountain height
		i = 0
		while (i <= height) :
			#  Inner loop is executing in through by 0..n
			j = 0
			while (j < n) :
				#  Include initial space
				self.includeSpace(height - i)
				#  Display the mountain element
				self.includeStar(i)
				#  Include end space
				self.includeSpace(height - i)
				j += 1
			
			#  Include new line
			print(end = "\n")
			i += 1
		
	

def main() :
	task = MountainPattern()
	#  Test Cases
	task.mountainSequence(1)
	task.mountainSequence(2)
	task.mountainSequence(4)
	task.mountainSequence(3)

if __name__ == "__main__": main()

input

 Given Size :  1

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

 Given Size :  2

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

 Given Size :  4

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

 Given Size :  3

    *         *         *
   * *       * *       * *
  * * *     * * *     * * *
 * * * *   * * * *   * * * *
* * * * * * * * * * * * * * *
#    Ruby Program
#    Mountain Sequence Pattern
class MountainPattern 
	#  Include n space
	def includeSpace(n) 
		i = 0
		while (i < n) 
			print(" ")
			i += 1
		end

	end

	#  Include n star with space
	def includeStar(n) 
		i = 0
		while (i < n) 
			print("* ")
			i += 1
		end

	end

	def mountainSequence(n) 
		if (n <= 0) 
			return
		end

		height = 5
		print("\n Given Size : ", n, "\n")
		#  Outer loop is executing in through by mountain height
		i = 0
		while (i <= height) 
			#  Inner loop is executing in through by 0..n
			j = 0
			while (j < n) 
				#  Include initial space
				self.includeSpace(height - i)
				#  Display the mountain element
				self.includeStar(i)
				#  Include end space
				self.includeSpace(height - i)
				j += 1
			end

			#  Include new line
			print("\n")
			i += 1
		end

	end

end

def main() 
	task = MountainPattern.new()
	#  Test Cases
	task.mountainSequence(1)
	task.mountainSequence(2)
	task.mountainSequence(4)
	task.mountainSequence(3)
end

main()

input

 Given Size : 1
          
    *     
   * *    
  * * *   
 * * * *  
* * * * * 

 Given Size : 2
                    
    *         *     
   * *       * *    
  * * *     * * *   
 * * * *   * * * *  
* * * * * * * * * * 

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

 Given Size : 3
                              
    *         *         *     
   * *       * *       * *    
  * * *     * * *     * * *   
 * * * *   * * * *   * * * *  
* * * * * * * * * * * * * * * 
/*
    Scala Program
    Mountain Sequence Pattern
*/
class MountainPattern()
{
	// Include n space
	def includeSpace(n: Int): Unit = {
		var i: Int = 0;
		while (i < n)
		{
			print(" ");
			i += 1;
		}
	}
	// Include n star with space
	def includeStar(n: Int): Unit = {
		var i: Int = 0;
		while (i < n)
		{
			print("* ");
			i += 1;
		}
	}
	def mountainSequence(n: Int): Unit = {
		if (n <= 0)
		{
			return;
		}
		var height: Int = 5;
		println("\n Given Size : " + n);
		// Outer loop is executing in through by mountain height
		var i: Int = 0;
		while (i <= height)
		{
			// Inner loop is executing in through by 0..n
			var j: Int = 0;
			while (j < n)
			{
				// Include initial space
				includeSpace(height - i);
				// Display the mountain element
				includeStar(i);
				// Include end space
				includeSpace(height - i);
				j += 1;
			}
			// Include new line
			print("\n");
			i += 1;
		}
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: MountainPattern = new MountainPattern();
		// Test Cases
		task.mountainSequence(1);
		task.mountainSequence(2);
		task.mountainSequence(4);
		task.mountainSequence(3);
	}
}

input

 Given Size : 1

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

 Given Size : 2

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

 Given Size : 4

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

 Given Size : 3

    *         *         *
   * *       * *       * *
  * * *     * * *     * * *
 * * * *   * * * *   * * * *
* * * * * * * * * * * * * * *
/*
    Swift 4 Program
    Mountain Sequence Pattern
*/
class MountainPattern
{
	// Include n space
	func includeSpace(_ n: Int)
	{
		var i = 0;
		while (i < n)
		{
			print(" ", terminator: "");
			i += 1;
		}
	}
	// Include n star with space
	func includeStar(_ n: Int)
	{
		var i = 0;
		while (i < n)
		{
			print("* ", terminator: "");
			i += 1;
		}
	}
	func mountainSequence(_ n: Int)
	{
		if (n <= 0)
		{
			return;
		}
		let height = 5;
		print("\n Given Size : ", n);
		// Outer loop is executing in through by mountain height
		var i = 0;
		while (i <= height)
		{
			// Inner loop is executing in through by 0..n
			var j = 0;
			while (j < n)
			{
				// Include initial space
				self.includeSpace(height - i);
				// Display the mountain element
				self.includeStar(i);
				// Include end space
				self.includeSpace(height - i);
				j += 1;
			}
			// Include new line
			print(terminator: "\n");
			i += 1;
		}
	}
}
func main()
{
	let task = MountainPattern();
	// Test Cases
	task.mountainSequence(1);
	task.mountainSequence(2);
	task.mountainSequence(4);
	task.mountainSequence(3);
}
main();

input

 Given Size :  1

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

 Given Size :  2

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

 Given Size :  4

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

 Given Size :  3

    *         *         *
   * *       * *       * *
  * * *     * * *     * * *
 * * * *   * * * *   * * * *
* * * * * * * * * * * * * * *
/*
    Kotlin Program
    Mountain Sequence Pattern
*/
class MountainPattern
{
	// Include n space
	fun includeSpace(n: Int): Unit
	{
		var i: Int = 0;
		while (i < n)
		{
			print(" ");
			i += 1;
		}
	}
	// Include n star with space
	fun includeStar(n: Int): Unit
	{
		var i: Int = 0;
		while (i < n)
		{
			print("* ");
			i += 1;
		}
	}
	fun mountainSequence(n: Int): Unit
	{
		if (n <= 0)
		{
			return;
		}
		val height: Int = 5;
		println("\n Given Size : " + n);
		// Outer loop is executing in through by mountain height
		var i: Int = 0;
		while (i <= height)
		{
			// Inner loop is executing in through by 0..n
			var j: Int = 0;
			while (j < n)
			{
				// Include initial space
				this.includeSpace(height - i);
				// Display the mountain element
				this.includeStar(i);
				// Include end space
				this.includeSpace(height - i);
				j += 1;
			}
			// Include new line
			print("\n");
			i += 1;
		}
	}
}
fun main(args: Array < String > ): Unit
{
	val task: MountainPattern = MountainPattern();
	// Test Cases
	task.mountainSequence(1);
	task.mountainSequence(2);
	task.mountainSequence(4);
	task.mountainSequence(3);
}

input

 Given Size : 1

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

 Given Size : 2

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

 Given Size : 4

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

 Given Size : 3

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


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