Program that receives a number and prints it out in large size
Question: Write a program that receives a number as input and prints it in large size on a same line as shown below in the image.
Examples :
Input : 0194 Output : ##### # ##### # # # ## # # # # # # # # # # # # # # ##### ##### # # # # # # # # # # ##### ##### # # Explanation: Each digit of the number has been printed in hash format Input : 0123456789 Output : ##### # ##### ##### # ##### ##### ##### ##### ##### # # ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # ##### ##### ##### ##### ##### #### ##### ##### # # # # # # # # # # # # # # # # # # # # # # # # # # ##### ##### ##### ##### # ##### ##### # ##### #
We use two-dimensional character array to store those hash strings for each digit. The for loop reads each digit and if-else checks the digit and prints each row of each digit from 2D char arrays on a same line. Then, proceeds to next line and works the same way until the whole design is printed.
C
// C program to print a number in large size #include<stdio.h> #include<string.h> #include<stdlib.h> #define H 7 // one extra room in the char array is required for storing '\0' #define W 8 void hashprint(char num[]) { int i, j, k; // declaring char 2D arrays and initializing // with hash-printed digits char zero[H][W]={" ##### ", // H=0 " # # ", // H=1 " # # ", // H=2 " # # ", // H=3 " # # ", // H=4 " # # ", // H=5 " ##### "},// H=6 one[H][W]={" # ", " ## ", " # ", " # ", " # ", " # ", " ##### "}, two[H][W]={" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "}, three[H][W]={" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "}, four[H][W]={" # ", " # # ", " # # ", " ##### ", " # ", " # ", " # "}, five[H][W]={" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "}, six[H][W]={" ##### ", " # ", " # ", " ##### ", " # # ", " # # ", " ##### "}, seven[H][W]={" ##### ", " # ", " # ", " #### ", " # ", " # ", " # "}, eight[H][W]={" ##### ", " # # ", " # # ", " ##### ", " # # ", " # # ", " ##### "}, nine[H][W]={" ##### ", " # # ", " # # ", " ##### ", " # ", " # ", " # "}; if (strlen(num) > 10) printf("\nYou must enter a number upto 10 digits.\nTry again!\n"); else { printf("\n"); k=1; j=0; //controls H of each digit while (k <= 7) //controls height { for (i=0; i<strlen(num); i++) //reads each digit { if (num[i] == '0') printf("%s", zero[j]); else if (num[i] == '1') printf("%s", one[j]); else if (num[i] == '2') printf("%s", two[j]); else if (num[i] == '3') printf("%s", three[j]); else if (num[i] == '4') printf("%s", four[j]); else if (num[i] == '5') printf("%s", five[j]); else if (num[i] == '6') printf("%s", six[j]); else if (num[i] == '7') printf("%s", seven[j]); else if (num[i] == '8') printf("%s", eight[j]); else if (num[i] == '9') printf("%s", nine[j]); } printf("\n"); k++; j++; } } } //Driver program to test above function int main() { // passing 0194 as string to function hashprint // you can pass whatever string you wish to hashprint("0194"); return 0; } |
Java
// JAVA Code for Program that receives a number // and prints it out in large size class GFG { public static void hashprint(String num) { int i, j, k; // declaring char 2D arrays and initializing // with hash-printed digits String zero[]={" ##### ", // H=0 " # # ", // H=1 " # # ", // H=2 " # # ", // H=3 " # # ", // H=4 " # # ", // H=5 " ##### "};// H=6 String one[]={" # ", " ## ", " # ", " # ", " # ", " # ", " ##### "}; String two[]={" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "}; String three[]={" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "}; String four[]={" # ", " # # ", " # # ", " ##### ", " # ", " # ", " # "}; String five[]={" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "}; String six[]={" ##### ", " # ", " # ", " ##### ", " # # ", " # # ", " ##### "}; String seven[]={" ##### ", " # ", " # ", " #### ", " # ", " # ", " # "}; String eight[]={" ##### ", " # # ", " # # ", " ##### ", " # # ", " # # ", " ##### "}; String nine[]={" ##### ", " # # ", " # # ", " ##### ", " # ", " # ", " # "}; if (num.length() > 10) System.out.println("\nYou must enter a number "+ "upto 10 digits.\nTry again!\n"); else { System.out.println(""); k = 1; j = 0; //controls H of each digit while (k <= 7) //controls height { for (i = 0; i < num.length(); i ++) //reads each digit { if (num.charAt(i) == '0') System.out.print(zero[j]); else if (num.charAt(i) == '1') System.out.print(one[j]); else if (num.charAt(i) == '2') System.out.print(two[j]); else if (num.charAt(i) == '3') System.out.print(three[j]); else if (num.charAt(i) == '4') System.out.print(four[j]); else if (num.charAt(i) == '5') System.out.print(five[j]); else if (num.charAt(i) == '6') System.out.print(six[j]); else if (num.charAt(i) == '7') System.out.print(seven[j]); else if (num.charAt(i) == '8') System.out.print(eight[j]); else if (num.charAt(i) == '9') System.out.print(nine[j]); } System.out.println(""); k ++; j ++; } } } /* Driver program to test above function */ public static void main(String[] args) { // passing 0194 as string to function hashprint // you can pass whatever string you wish to hashprint("0194"); } } // This code is contributed by Arnav Kr. Mandal. |
C#
// C# Code for Program that // receives a number and prints // it out in large size using System; class GFG { public static void hashprint(string num) { int i, j, k; // declaring char 2D arrays // and initializing with // hash-printed digits String []zero={" ##### ", // H=0 " # # ", // H=1 " # # ", // H=2 " # # ", // H=3 " # # ", // H=4 " # # ", // H=5 " ##### "};// H=6 String []one={" # ", " ## ", " # ", " # ", " # ", " # ", " ##### "}; String []two={" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "}; String []three={" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "}; String []four={" # ", " # # ", " # # ", " ##### ", " # ", " # ", " # "}; String []five={" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "}; String []six={" ##### ", " # ", " # ", " ##### ", " # # ", " # # ", " ##### "}; String []seven={" ##### ", " # ", " # ", " #### ", " # ", " # ", " # "}; String []eight={" ##### ", " # # ", " # # ", " ##### ", " # # ", " # # ", " ##### "}; String []nine={" ##### ", " # # ", " # # ", " ##### ", " # ", " # ", " # "}; if (num.Length > 10) Console.WriteLine("\nYou must enter a number "+ "upto 10 digits.\nTry again!\n"); else { Console.WriteLine(""); k = 1; j = 0; //controls H of each digit while ($k <= 7) //controls height { //reads each digit for ($i = 0; $i < strlen($num); $i++) { if (num[i] == '0') Console.Write(zero[j]); else if (num[i] == '1') Console.Write(one[j]); else if (num[i] == '2') Console.Write(two[j]); else if (num[i] == '3') Console.Write(three[j]); else if (num[i] == '4') Console.Write(four[j]); else if (num[i] == '5') Console.Write(five[j]); else if (num[i] == '6') Console.Write(six[j]); else if (num[i] == '7') Console.Write(seven[j]); else if (num[i] == '8') Console.Write(eight[j]); else if (num[i] == '9') Console.Write(nine[j]); } Console.WriteLine(""); k ++; j ++; } } } // Driver Code public static void Main() { // passing 0194 as string to // function hashprint you can // pass whatever string you wish to hashprint("0194"); } } // This code is contributed by Sam007 |
PHP
<?php // PHP program to print // a number in large size $H = 7; // one extra room in the // char array is required // for storing '\0' $W = 8; function hashprint($num) { global $H; global $W; $i; $j; $k; // declaring char 2D arrays // and initializing with // hash-printed digits $zero= array(" ##### ", // H=0 " # # ", // H=1 " # # ", // H=2 " # # ", // H=3 " # # ", // H=4 " # # ", // H=5 " ##### ");// H=6 $one= array(" # ", " ## ", " # ", " # ", " # ", " # ", " ##### "); $two= array(" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "); $three= array(" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "); $four= array(" # ", " # # ", " # # ", " ##### ", " # ", " # ", " # "); $five= array(" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "); $six= array(" ##### ", " # ", " # ", " ##### ", " # # ", " # # ", " ##### "); $seven= array(" ##### ", " # ", " # ", " #### ", " # ", " # ", " # "); $eight= array(" ##### ", " # # ", " # # ", " ##### ", " # # ", " # # ", " ##### "); $nine= array(" ##### ", " # # ", " # # ", " ##### ", " # ", " # ", " # "); if (strlen($num) > 10) echo "\nYou must enter a " . "number upto 10 digits. \nTry again!\n"; else { echo "\n"; $k = 1; $j = 0; //controls H of each digit while ($k <= 7) //controls height { //reads each digit for ($i = 0; $i < strlen($num); $i++) { if ($num[$i] == '0') echo $zero[$j]; else if ($num[$i] == '1') echo $one[$j]; else if ($num[$i] == '2') echo $two[$j]; else if ($num[$i] == '3') echo $three[$j]; else if ($num[$i] == '4') echo $four[$j]; else if ($num[$i] == '5') echo $five[$j]; else if ($num[$i] == '6') echo $six[$j]; else if ($num[$i] == '7') echo $seven[$j]; else if ($num[$i] == '8') echo $eight[$j]; else if ($num[$i] == '9') echo $nine[$j]; } echo "\n"; $k++; $j++; } } } // Driver Code // passing 0194 as string // to function hashprint // you can pass whatever // string you wish to hashprint("0194"); // This code is contributed by ajit ?> |
Output:
##### # ##### # # # ## # # # # # # # # # # # # # # ##### ##### # # # # # # # # # # ##### ##### # #
This article has been contributed by Mayukh Datta. If you like GeeksforGeeks and would like to contribute an unique article, you can also write using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
To contact the contributer of this article, follow this link to his blog – thecoducer
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Recommended Posts:
- C/C++ program to find the size of int, float, double and char
- Program to check whether the given number is Buzz Number or not
- Program for n-th odd number
- Program for n-th even number
- Program for factorial of a number
- Last digit of Product of two Large or Small numbers (a * b)
- Program to check for Peterson number
- Program to print number pattern
- Program to print Even Odd Number Pyramid
- Program to find the Nth number of the series 2, 10, 24, 44, 70.....
- Program for centered nonagonal number
- Program for Centered Icosahedral Number
- Program to print all the numbers divisible by 3 and 5 for a given number
- Program to calculate product of digits of a number
- Program to Convert Hexadecimal Number to Binary


