Thursday, July 4, 2024
HomeData ModellingData Structure & AlgorithmProgram that receives a number and prints it out in large size

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<bits/stdc++.h>
using namespace std;
#define H 7
  
// one extra room in the char array is required for storing '\0'
#define W 8 
  
void hashprint(string 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 (num.length() > 10)
           cout<<"\nYou must enter a number upto 10 digits.\nTry again!\n";
            
        else
        {
            cout<<"\n";
            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[i] == '0')
                        cout<<zero[j];
                    else if (num[i] == '1')
                        cout<<one[j];
                    else if (num[i] == '2')
                        cout<<two[j];
                    else if (num[i] == '3')
                        cout<<three[j];
                    else if (num[i] == '4')
                        cout<<four[j];
                    else if (num[i] == '5')
                        cout<<five[j];
                    else if (num[i] == '6')
                        cout<<six[j];
                    else if (num[i] == '7')
                        cout<<seven[j];
                    else if (num[i] == '8')
                        cout<<eight[j];
                    else if (num[i] == '9')
                        cout<<nine[j];
                }
                cout<<"\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;
}
  
// This code is contributed by poojaagarwal2.


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.


Python3




# Python program to print a number in large size
  
H = 7
  
# one extra room in the char array is required for storing '\0'
W = 8
  
def hashprint(num):
  
    # declaring char 2D arrays and initializing
    # with hash-printed digits
    zero  =  [" ##### ", # H=0
              " #   # ", # H=1
              " #   # ", # H=2
              " #   # ", # H=3
              " #   # ", # H=4
              " #   # ", # H=5
              " ##### "]# H=6
  
    one  = ["   #   ",
            "  ##   ",
            "   #   ",
            "   #   ",
            "   #   ",
            "   #   ",
            " ##### "]
  
    two  =  [" ##### ",
             "       # ",
             "       # ",
             " ##### ",
             " #     ",
             " #     ",
             " ##### "]
  
    three  =  [" ##### ",
               "     # ",
               "     # ",
               " ##### ",
               "     # ",
               "     # ",
               " ##### "]
  
    four  =  [" #     ",
              " #   # ",
              " #   # ",
              " ##### ",
              "      # ",
              "      # ",
              "      # "]
  
    five  =  [" ##### ",
              " #      ",
              " #      ",
              " ##### ",
              "        # ",
              "        # ",
              " ##### "]
  
    six  =  [" ##### ",
             " #     ",
             " #     ",
             " ##### ",
             " #   # ",
             " #   # ",
             " ##### "]
  
    seven  =  [" ##### ",
               "     # ",
               "     # ",
               "  #### ",
               "     # ",
               "     # ",
               "     # "]
  
    eight  =  [" ##### ",
               " #   # ",
               " #   # ",
               " ##### ",
               " #   # ",
               " #   # ",
               " ##### "]
  
    nine  =  [" ##### ",
              " #   # ",
              " #   # ",
              " ##### ",
              "     # ",
              "     # ",
              "     # "]
  
  
    if (len(num) > 10):
        print()
        print("You must enter a number upto 10 digits.")
        print("Try again!")
      
    else:
        print()
        k=1
        j=0 #controls H of each digit
        while (k <= 7): #controls height
              
            for i in range(len(num)): #reads each digit
              
                if(num[i] == '0'):
                    print(zero[j],end = "")
                elif (num[i] == '1'):
                    print(one[j],end = "")
                elif (num[i] == '2'):
                    print(two[j],end = "")
                elif (num[i] == '3'):
                    print(three[j],end = "")
                elif (num[i] == '4'):
                    print(four[j],end = "")
                elif (num[i] == '5'):
                    print(five[j],end = "")
                elif (num[i] == '6'):
                    print(six[j],end = "")
                elif (num[i] == '7'):
                    print(seven[j],end = "")
                elif (num[i] == '8'):
                    print(eight[j],end = "")
                elif (num[i] == '9'):
                    print(nine[j],end = "")
              
            print()
            k += 1
            j += 1
              
          
# Driver program to test above function
  
# passing 0194 as string to function hashprint
# you can pass whatever string you wish to
  
hashprint("0194")
  
# This code is contributed by shinjanpatra


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: 
 

 #####    #    #####  #
 #   #   ##    #   #  #   #
 #   #    #    #   #  #   #
 #   #    #    #####  #####
 #   #    #        #      #
 #   #    #        #      #
 #####  #####      #      #

Time Complexity: O(N), Here N is the length of the string.

Auxiliary Space: O(1), As constant extra space is used.

This article has been contributed by Mayukh Datta. If you like neveropen and would like to contribute an unique article, you can also write using write.neveropen.co.za or mail your article to review-team@neveropen.co.za. See your article appearing on the neveropen main page and help other Geeks.
To contact the contributor 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.
 

Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!

Shaida Kate Naidoo
am passionate about learning the latest technologies available to developers in either a Front End or Back End capacity. I enjoy creating applications that are well designed and responsive, in addition to being user friendly. I thrive in fast paced environments. With a diverse educational and work experience background, I excel at collaborating with teams both local and international. A versatile developer with interests in Software Development and Software Engineering. I consider myself to be adaptable and a self motivated learner. I am interested in new programming technologies, and continuous self improvement.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments