Open In App

Program that receives a number and prints it out in large size

Improve
Improve
Like Article
Like
Save
Share
Report

Write a program that receives a number n as input and prints it in large size on a same line as shown below in the image.

Examples : 

Input : n = 0194
Output :

0194pattern-(3)

Input : n = 0123456789
Output :

0123456789Pattern-(1)

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 up to 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;
}


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


Javascript




// JavaScript code for a program that receives a number
// and prints it out in large size
 
function hashprint(num) {
    // Declaring arrays for hash-printed digits
    const zero = [
        " ##### ",
        " #   # ",
        " #   # ",
        " #   # ",
        " #   # ",
        " #   # ",
        " ##### "
    ];
 
    const one = [
        "   #   ",
        "  ##   ",
        "   #   ",
        "   #   ",
        "   #   ",
        "   #   ",
        " ##### "
    ];
 
    const two = [
        " ##### ",
        "     # ",
        "     # ",
        " ##### ",
        " #     ",
        " #     ",
        " ##### "
    ];
 
    const three = [
        " ##### ",
        "     # ",
        "     # ",
        " ##### ",
        "     # ",
        "     # ",
        " ##### "
    ];
 
    const four = [
        " #     ",
        " #   # ",
        " #   # ",
        " ##### ",
        "     # ",
        "     # ",
        "     # "
    ];
 
    const five = [
        " ##### ",
        " #     ",
        " #     ",
        " ##### ",
        "     # ",
        "     # ",
        " ##### "
    ];
 
    const six = [
        " ##### ",
        " #     ",
        " #     ",
        " ##### ",
        " #   # ",
        " #   # ",
        " ##### "
    ];
 
    const seven = [
        " ##### ",
        "     # ",
        "     # ",
        "  #### ",
        "     # ",
        "     # ",
        "     # "
    ];
 
    const eight = [
        " ##### ",
        " #   # ",
        " #   # ",
        " ##### ",
        " #   # ",
        " #   # ",
        " ##### "
    ];
 
    const nine = [
        " ##### ",
        " #   # ",
        " #   # ",
        " ##### ",
        "     # ",
        "     # ",
        "     # "
    ];
 
    if (num.length > 10) {
        console.log("\nYou must enter a number up to 10 digits.\nTry again!\n");
    } else {
        console.log("");
         
        let k = 1;
        let j = 0; // Controls height of each digit
        while (k <= 7) { // Controls height
            for (let i = 0; i < num.length; i++) { // Reads each digit
                if (num.charAt(i) === '0')
                    process.stdout.write(zero[j]);
                else if (num.charAt(i) === '1')
                    process.stdout.write(one[j]);
                else if (num.charAt(i) === '2')
                    process.stdout.write(two[j]);
                else if (num.charAt(i) === '3')
                    process.stdout.write(three[j]);
                else if (num.charAt(i) === '4')
                    process.stdout.write(four[j]);
                else if (num.charAt(i) === '5')
                    process.stdout.write(five[j]);
                else if (num.charAt(i) === '6')
                    process.stdout.write(six[j]);
                else if (num.charAt(i) === '7')
                    process.stdout.write(seven[j]);
                else if (num.charAt(i) === '8')
                    process.stdout.write(eight[j]);
                else if (num.charAt(i) === '9')
                    process.stdout.write(nine[j]);
            }
             
            console.log("");
            k++;
            j++;
        }
    }
}
 
// Driver program to test the hashprint function
// Passing "0194" as a string to the function hashprint
// You can pass whatever string you wish to
hashprint("0194");


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 GeeksforGeeks and would like to contribute an unique article, you can also write using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks 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.
 



Last Updated : 18 Jan, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads