Print digit pattern

Here given code implementation process.

//  C program for
//  Print digit pattern
#include <stdio.h>

void printValue(int num)
{
	if (num > 0)
	{
		// Recursive function calling
		printValue(num / 10);
		int digit = num % 10;
		// Include initial value
		printf("\n#");
		// Print the *by given digit
		for (int i = 0; i < digit; ++i)
		{
			printf("*");
		}
	}
}
void printPattern(int num)
{
	if (num <= 0)
	{
		return;
	}
	// Display given number
	printf("\nGiven num : %d ", num);
	printValue(num);
}
int main(int argc, char
	const *argv[])
{
	// Test
	printPattern(53235);
	printPattern(84033);
	return 0;
}

Output

Given num : 53235
#*****
#***
#**
#***
#*****
Given num : 84033
#********
#****
#
#***
#***
/*
    Java Program
    Print digit pattern
*/
public class Pattern
{
	public void printValue(int num)
	{
		if (num > 0)
		{
			// Recursive function calling
			printValue(num / 10);
			int digit = num % 10;
			// Include initial value
			System.out.print("\n#");
			// Print the *by given digit
			for (int i = 0; i < digit; ++i)
			{
				System.out.print("*");
			}
		}
	}
	public void printPattern(int num)
	{
		if (num <= 0)
		{
			return;
		}
		// Display given number
		System.out.print("\nGiven num : " + num);
		printValue(num);
	}
	public static void main(String[] args)
	{
		Pattern task = new Pattern();
		// Test
		task.printPattern(53235);
		task.printPattern(84033);
	}
}

Output

Given num : 53235
#*****
#***
#**
#***
#*****
Given num : 84033
#********
#****
#
#***
#***
// Include header file
#include <iostream>
using namespace std;
/*
    C++ Program
    Print digit pattern
*/
class Pattern
{
	public: void printValue(int num)
	{
		if (num > 0)
		{
			// Recursive function calling
			this->printValue(num / 10);
			int digit = num % 10;
			// Include initial value
			cout << "\n#";
			// Print the *by given digit
			for (int i = 0; i < digit; ++i)
			{
				cout << "*";
			}
		}
	}
	void printPattern(int num)
	{
		if (num <= 0)
		{
			return;
		}
		// Display given number
		cout << "\nGiven num : " << num;
		this->printValue(num);
	}
};
int main()
{
	Pattern *task = new Pattern();
	// Test
	task->printPattern(53235);
	task->printPattern(84033);
	return 0;
}

Output

Given num : 53235
#*****
#***
#**
#***
#*****
Given num : 84033
#********
#****
#
#***
#***
// Include namespace system
using System;
/*
    Csharp Program
    Print digit pattern
*/
public class Pattern
{
	public void printValue(int num)
	{
		if (num > 0)
		{
			// Recursive function calling
			this.printValue(num / 10);
			int digit = num % 10;
			// Include initial value
			Console.Write("\n#");
			// Print the *by given digit
			for (int i = 0; i < digit; ++i)
			{
				Console.Write("*");
			}
		}
	}
	public void printPattern(int num)
	{
		if (num <= 0)
		{
			return;
		}
		// Display given number
		Console.Write("\nGiven num : " + num);
		this.printValue(num);
	}
	public static void Main(String[] args)
	{
		Pattern task = new Pattern();
		// Test
		task.printPattern(53235);
		task.printPattern(84033);
	}
}

Output

Given num : 53235
#*****
#***
#**
#***
#*****
Given num : 84033
#********
#****
#
#***
#***
package main
import "fmt"
/*
    Go Program
    Print digit pattern
*/
type Pattern struct {}
func getPattern() * Pattern {
	var me *Pattern = &Pattern {}
	return me
}
func(this Pattern) printValue(num int) {
	if num > 0 {
		// Recursive function calling
		this.printValue(num / 10)
		var digit int = num % 10
		// Include initial value
		fmt.Print("\n#")
		// Print the *by given digit
		for i := 0 ; i < digit ; i++ {
			fmt.Print("*")
		}
	}
}
func(this Pattern) printPattern(num int) {
	if num <= 0 {
		return
	}
	// Display given number
	fmt.Print("\nGiven num : ", num)
	this.printValue(num)
}
func main() {
	var task * Pattern = getPattern()
	// Test
	task.printPattern(53235)
	task.printPattern(84033)
}

Output

Given num : 53235
#*****
#***
#**
#***
#*****
Given num : 84033
#********
#****
#
#***
#***
<?php
/*
    Php Program
    Print digit pattern
*/
class Pattern
{
	public	function printValue($num)
	{
		if ($num > 0)
		{
			// Recursive function calling
			$this->printValue((int)($num / 10));
			$digit = $num % 10;
			// Include initial value
			echo("\n#");
			// Print the *by given digit
			for ($i = 0; $i < $digit; ++$i)
			{
				echo("*");
			}
		}
	}
	public	function printPattern($num)
	{
		if ($num <= 0)
		{
			return;
		}
		// Display given number
		echo("\nGiven num : ".$num);
		$this->printValue($num);
	}
}

function main()
{
	$task = new Pattern();
	// Test
	$task->printPattern(53235);
	$task->printPattern(84033);
}
main();

Output

Given num : 53235
#*****
#***
#**
#***
#*****
Given num : 84033
#********
#****
#
#***
#***
/*
    Node JS Program
    Print digit pattern
*/
class Pattern
{
	printValue(num)
	{
		if (num > 0)
		{
			// Recursive function calling
			this.printValue(parseInt(num / 10));
			var digit = num % 10;
			// Include initial value
			process.stdout.write("\n#");
			// Print the *by given digit
			for (var i = 0; i < digit; ++i)
			{
				process.stdout.write("*");
			}
		}
	}
	printPattern(num)
	{
		if (num <= 0)
		{
			return;
		}
		// Display given number
		process.stdout.write("\nGiven num : " + num);
		this.printValue(num);
	}
}

function main()
{
	var task = new Pattern();
	// Test
	task.printPattern(53235);
	task.printPattern(84033);
}
main();

Output

Given num : 53235
#*****
#***
#**
#***
#*****
Given num : 84033
#********
#****
#
#***
#***
#    Python 3 Program
#    Print digit pattern
class Pattern :
	def printValue(self, num) :
		if (num > 0) :
			#  Recursive function calling
			self.printValue(int(num / 10))
			digit = num % 10
			#  Include initial value
			print("\n#", end = "")
			i = 0
			#  Print the *by given digit
			while (i < digit) :
				print("*", end = "")
				i += 1
			
		
	
	def printPattern(self, num) :
		if (num <= 0) :
			return
		
		#  Display given number
		print("\nGiven num : ", num, end = "")
		self.printValue(num)
	

def main() :
	task = Pattern()
	#  Test
	task.printPattern(53235)
	task.printPattern(84033)

if __name__ == "__main__": main()

Output

Given num :  53235
#*****
#***
#**
#***
#*****
Given num :  84033
#********
#****
#
#***
#***
#    Ruby Program
#    Print digit pattern
class Pattern 
	def printValue(num) 
		if (num > 0) 
			#  Recursive function calling
			self.printValue(num / 10)
			digit = num % 10
			#  Include initial value
			print("\n#")
			i = 0
			#  Print the *by given digit
			while (i < digit) 
				print("*")
				i += 1
			end

		end

	end

	def printPattern(num) 
		if (num <= 0) 
			return
		end

		#  Display given number
		print("\nGiven num : ", num)
		self.printValue(num)
	end

end

def main() 
	task = Pattern.new()
	#  Test
	task.printPattern(53235)
	task.printPattern(84033)
end

main()

Output

Given num : 53235
#*****
#***
#**
#***
#*****
Given num : 84033
#********
#****
#
#***
#***
/*
    Scala Program
    Print digit pattern
*/
class Pattern()
{
	def printValue(num: Int): Unit = {
		if (num > 0)
		{
			// Recursive function calling
			printValue(num / 10);
			var digit: Int = num % 10;
			// Include initial value
			print("\n#");
			var i: Int = 0;
			// Print the *by given digit
			while (i < digit)
			{
				print("*");
				i += 1;
			}
		}
	}
	def printPattern(num: Int): Unit = {
		if (num <= 0)
		{
			return;
		}
		// Display given number
		print("\nGiven num : " + num);
		printValue(num);
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: Pattern = new Pattern();
		// Test
		task.printPattern(53235);
		task.printPattern(84033);
	}
}

Output

Given num : 53235
#*****
#***
#**
#***
#*****
Given num : 84033
#********
#****
#
#***
#***
/*
    Swift 4 Program
    Print digit pattern
*/
class Pattern
{
	func printValue(_ num: Int)
	{
		if (num > 0)
		{
			// Recursive function calling
			self.printValue(num / 10);
			let digit: Int = num % 10;
			// Include initial value
			print("\n#", terminator: "");
			var i: Int = 0;
			// Print the *by given digit
			while (i < digit)
			{
				print("*", terminator: "");
				i += 1;
			}
		}
	}
	func printPattern(_ num: Int)
	{
		if (num <= 0)
		{
			return;
		}
		// Display given number
		print("\nGiven num : ", num, terminator: "");
		self.printValue(num);
	}
}
func main()
{
	let task: Pattern = Pattern();
	// Test
	task.printPattern(53235);
	task.printPattern(84033);
}
main();

Output

Given num :  53235
#*****
#***
#**
#***
#*****
Given num :  84033
#********
#****
#
#***
#***
/*
    Kotlin Program
    Print digit pattern
*/
class Pattern
{
	fun printValue(num: Int): Unit
	{
		if (num > 0)
		{
			// Recursive function calling
			this.printValue(num / 10);
			val digit: Int = num % 10;
			// Include initial value
			print("\n#");
			var i: Int = 0;
			// Print the *by given digit
			while (i < digit)
			{
				print("*");
				i += 1;
			}
		}
	}
	fun printPattern(num: Int): Unit
	{
		if (num <= 0)
		{
			return;
		}
		// Display given number
		print("\nGiven num : " + num);
		this.printValue(num);
	}
}
fun main(args: Array < String > ): Unit
{
	val task: Pattern = Pattern();
	// Test
	task.printPattern(53235);
	task.printPattern(84033);
}

Output

Given num : 53235
#*****
#***
#**
#***
#*****
Given num : 84033
#********
#****
#
#***
#***


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