Print the double sided staircase pattern
Here given code implementation process.
// C program for
// Print the double sided staircase pattern
#include <stdio.h>
// This is display given text of given length
void includeCharacter(char *icon, int n)
{
for (int i = 0; i < n; ++i)
{
printf("%s", icon);
}
}
void printPattern(int height)
{
printf("\n Height : %d\n\n", height);
// Outer loop control the row operation
for (int i = 0; i < height; ++i)
{
// Include space
includeCharacter(" ", (height *2) - i *2);
// Inner loop control the column operation
for (int k = 0; k <= i; ++k)
{
// Add intermediate value
printf("░░");
}
// Include pattern value
includeCharacter("░", i *2);
printf("\n");
}
}
int main(int argc, char
const *argv[])
{
// Test
printPattern(5);
printPattern(8);
return 0;
}
Output
Height : 5
░░
░░░░░░
░░░░░░░░░░
░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
Height : 8
░░
░░░░░░
░░░░░░░░░░
░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
/*
Java Program
Print the double sided staircase pattern
*/
public class Pattern
{
// This is display given text of given length
public void includeCharacter(String icon, int n)
{
for (int i = 0; i < n; ++i)
{
System.out.print(icon);
}
}
public void printPattern(int height)
{
System.out.print("\n Height : " + height + "\n\n");
// Outer loop control the row operation
for (int i = 0; i < height; ++i)
{
// Include space
includeCharacter(" ", (height * 2) - i * 2);
// Inner loop control the column operation
for (int k = 0; k <= i; ++k)
{
// Add intermediate value
System.out.print("░░");
}
// Include pattern value
includeCharacter("░", i * 2);
System.out.print("\n");
}
}
public static void main(String[] args)
{
Pattern task = new Pattern();
// Test
task.printPattern(5);
task.printPattern(8);
}
}
Output
Height : 5
░░
░░░░░░
░░░░░░░░░░
░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
Height : 8
░░
░░░░░░
░░░░░░░░░░
░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
// Include header file
#include <iostream>
using namespace std;
/*
C++ Program
Print the double sided staircase pattern
*/
class Pattern
{
public:
// This is display given text of given length
void includeCharacter(string icon, int n)
{
for (int i = 0; i < n; ++i)
{
cout << icon;
}
}
void printPattern(int height)
{
cout << "\n Height : " << height << "\n\n";
// Outer loop control the row operation
for (int i = 0; i < height; ++i)
{
// Include space
this->includeCharacter(" ", (height *2) - i *2);
// Inner loop control the column operation
for (int k = 0; k <= i; ++k)
{
// Add intermediate value
cout << "░░";
}
// Include pattern value
this->includeCharacter("░", i *2);
cout << "\n";
}
}
};
int main()
{
Pattern *task = new Pattern();
// Test
task->printPattern(5);
task->printPattern(8);
return 0;
}
Output
Height : 5
░░
░░░░░░
░░░░░░░░░░
░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
Height : 8
░░
░░░░░░
░░░░░░░░░░
░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
// Include namespace system
using System;
/*
Csharp Program
Print the double sided staircase pattern
*/
public class Pattern
{
// This is display given text of given length
public void includeCharacter(String icon, int n)
{
for (int i = 0; i < n; ++i)
{
Console.Write(icon);
}
}
public void printPattern(int height)
{
Console.Write("\n Height : " + height + "\n\n");
// Outer loop control the row operation
for (int i = 0; i < height; ++i)
{
// Include space
this.includeCharacter(" ", (height * 2) - i * 2);
// Inner loop control the column operation
for (int k = 0; k <= i; ++k)
{
// Add intermediate value
Console.Write("░░");
}
// Include pattern value
this.includeCharacter("░", i * 2);
Console.Write("\n");
}
}
public static void Main(String[] args)
{
Pattern task = new Pattern();
// Test
task.printPattern(5);
task.printPattern(8);
}
}
Output
Height : 5
░░
░░░░░░
░░░░░░░░░░
░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
Height : 8
░░
░░░░░░
░░░░░░░░░░
░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
package main
import "fmt"
/*
Go Program
Print the double sided staircase pattern
*/
type Pattern struct {}
func getPattern() * Pattern {
var me *Pattern = &Pattern {}
return me
}
// This is display given text of given length
func(this Pattern) includeCharacter(icon string, n int) {
for i := 0 ; i < n ; i++ {
fmt.Print(icon)
}
}
func(this Pattern) printPattern(height int) {
fmt.Print("\n Height : ", height, "\n\n")
// Outer loop control the row operation
for i := 0 ; i < height ; i++ {
// Include space
this.includeCharacter(" ", (height * 2) - i * 2)
// Inner loop control the column operation
for k := 0 ; k <= i ; k++ {
// Add intermediate value
fmt.Print("░░")
}
// Include pattern value
this.includeCharacter("░", i * 2)
fmt.Print("\n")
}
}
func main() {
var task * Pattern = getPattern()
// Test
task.printPattern(5)
task.printPattern(8)
}
Output
Height : 5
░░
░░░░░░
░░░░░░░░░░
░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
Height : 8
░░
░░░░░░
░░░░░░░░░░
░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
<?php
/*
Php Program
Print the double sided staircase pattern
*/
class Pattern
{
// This is display given text of given length
public function includeCharacter($icon, $n)
{
for ($i = 0; $i < $n; ++$i)
{
echo($icon);
}
}
public function printPattern($height)
{
echo("\n Height : ".$height."\n\n");
// Outer loop control the row operation
for ($i = 0; $i < $height; ++$i)
{
// Include space
$this->includeCharacter(" ", ($height * 2) - $i * 2);
// Inner loop control the column operation
for ($k = 0; $k <= $i; ++$k)
{
// Add intermediate value
echo("░░");
}
// Include pattern value
$this->includeCharacter("░", $i * 2);
echo("\n");
}
}
}
function main()
{
$task = new Pattern();
// Test
$task->printPattern(5);
$task->printPattern(8);
}
main();
Output
Height : 5
░░
░░░░░░
░░░░░░░░░░
░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
Height : 8
░░
░░░░░░
░░░░░░░░░░
░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
/*
Node JS Program
Print the double sided staircase pattern
*/
class Pattern
{
// This is display given text of given length
includeCharacter(icon, n)
{
for (var i = 0; i < n; ++i)
{
process.stdout.write(icon);
}
}
printPattern(height)
{
process.stdout.write("\n Height : " + height + "\n\n");
// Outer loop control the row operation
for (var i = 0; i < height; ++i)
{
// Include space
this.includeCharacter(" ", (height * 2) - i * 2);
// Inner loop control the column operation
for (var k = 0; k <= i; ++k)
{
// Add intermediate value
process.stdout.write("░░");
}
// Include pattern value
this.includeCharacter("░", i * 2);
process.stdout.write("\n");
}
}
}
function main()
{
var task = new Pattern();
// Test
task.printPattern(5);
task.printPattern(8);
}
main();
Output
Height : 5
░░
░░░░░░
░░░░░░░░░░
░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
Height : 8
░░
░░░░░░
░░░░░░░░░░
░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
# Python 3 Program
# Print the double sided staircase pattern
class Pattern :
# This is display given text of given length
def includeCharacter(self, icon, n) :
i = 0
while (i < n) :
print(icon, end = "")
i += 1
def printPattern(self, height) :
print("\n Height : ", height ,"\n")
i = 0
# Outer loop control the row operation
while (i < height) :
# Include space
self.includeCharacter(" ", (height * 2) - i * 2)
k = 0
# Inner loop control the column operation
while (k <= i) :
# Add intermediate value
print("░░", end = "")
k += 1
# Include pattern value
self.includeCharacter("░", i * 2)
print(end = "\n")
i += 1
def main() :
task = Pattern()
# Test
task.printPattern(5)
task.printPattern(8)
if __name__ == "__main__": main()
Output
Height : 5
░░
░░░░░░
░░░░░░░░░░
░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
Height : 8
░░
░░░░░░
░░░░░░░░░░
░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
# Ruby Program
# Print the double sided staircase pattern
class Pattern
# This is display given text of given length
def includeCharacter(icon, n)
i = 0
while (i < n)
print(icon)
i += 1
end
end
def printPattern(height)
print("\n Height : ", height ,"\n\n")
i = 0
# Outer loop control the row operation
while (i < height)
# Include space
self.includeCharacter(" ", (height * 2) - i * 2)
k = 0
# Inner loop control the column operation
while (k <= i)
# Add intermediate value
print("░░")
k += 1
end
# Include pattern value
self.includeCharacter("░", i * 2)
print("\n")
i += 1
end
end
end
def main()
task = Pattern.new()
# Test
task.printPattern(5)
task.printPattern(8)
end
main()
Output
Height : 5
░░
░░░░░░
░░░░░░░░░░
░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
Height : 8
░░
░░░░░░
░░░░░░░░░░
░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
/*
Scala Program
Print the double sided staircase pattern
*/
class Pattern()
{
// This is display given text of given length
def includeCharacter(icon: String, n: Int): Unit = {
var i: Int = 0;
while (i < n)
{
print(icon);
i += 1;
}
}
def printPattern(height: Int): Unit = {
print("\n Height : " + height + "\n\n");
var i: Int = 0;
// Outer loop control the row operation
while (i < height)
{
// Include space
includeCharacter(" ", (height * 2) - i * 2);
var k: Int = 0;
// Inner loop control the column operation
while (k <= i)
{
// Add intermediate value
print("░░");
k += 1;
}
// Include pattern value
includeCharacter("░", i * 2);
print("\n");
i += 1;
}
}
}
object Main
{
def main(args: Array[String]): Unit = {
var task: Pattern = new Pattern();
// Test
task.printPattern(5);
task.printPattern(8);
}
}
Output
Height : 5
░░
░░░░░░
░░░░░░░░░░
░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
Height : 8
░░
░░░░░░
░░░░░░░░░░
░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
/*
Swift 4 Program
Print the double sided staircase pattern
*/
class Pattern
{
// This is display given text of given length
func includeCharacter(_ icon: String, _ n: Int)
{
var i: Int = 0;
while (i < n)
{
print(icon, terminator: "");
i += 1;
}
}
func printPattern(_ height: Int)
{
print("\n Height : ", height ,"\n");
var i: Int = 0;
// Outer loop control the row operation
while (i < height)
{
// Include space
self.includeCharacter(" ", (height * 2) - i * 2);
var k: Int = 0;
// Inner loop control the column operation
while (k <= i)
{
// Add intermediate value
print("░░", terminator: "");
k += 1;
}
// Include pattern value
self.includeCharacter("░", i * 2);
print(terminator: "\n");
i += 1;
}
}
}
func main()
{
let task: Pattern = Pattern();
// Test
task.printPattern(5);
task.printPattern(8);
}
main();
Output
Height : 5
░░
░░░░░░
░░░░░░░░░░
░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
Height : 8
░░
░░░░░░
░░░░░░░░░░
░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
/*
Kotlin Program
Print the double sided staircase pattern
*/
class Pattern
{
// This is display given text of given length
fun includeCharacter(icon: String, n: Int): Unit
{
var i: Int = 0;
while (i < n)
{
print(icon);
i += 1;
}
}
fun printPattern(height: Int): Unit
{
print("\n Height : " + height + "\n\n");
var i: Int = 0;
// Outer loop control the row operation
while (i < height)
{
// Include space
this.includeCharacter(" ", (height * 2) - i * 2);
var k: Int = 0;
// Inner loop control the column operation
while (k <= i)
{
// Add intermediate value
print("░░");
k += 1;
}
// Include pattern value
this.includeCharacter("░", i * 2);
print("\n");
i += 1;
}
}
}
fun main(args: Array < String > ): Unit
{
val task: Pattern = Pattern();
// Test
task.printPattern(5);
task.printPattern(8);
}
Output
Height : 5
░░
░░░░░░
░░░░░░░░░░
░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
Height : 8
░░
░░░░░░
░░░░░░░░░░
░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
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