
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ program to Zoom digits of an integer
Zooming digits means printing the digits of a given number in an enlarged form using special characters. In this article, we will learn to print (display) enlarged (zoomed) form of the digits of a given number.
Below is the representation of digits 01438 in zoom format,

Example of Zoom Digits in Integers Form
To generate the zoomed digit, we define the pattern logic for each digit based on its respective function prototype. Then, we create a function that sets the switch-case logic which processes the selected digit based on either user input or a given number.
In this example, we first create prototypes for all the digit functions, with each prototype representing a different set of digits ranging from 0 to 9:
#include <bits/stdc++.h> using namespace std; // Function prototype for all printing digit functions void print_zero(); void print_one(); void print_two(); void print_three(); void print_four(); void print_five(); void print_six(); void print_seven(); void print_eight(); void print_nine(); void zoom_digit(int number); // Function to print digit '0' void print_zero() { for (int i=0; i<5; i++) { for (int j=0; j<5; j++) { if (i==0 || i==4 || j==0 || j==4) cout << '#'; else cout << " "; } cout << endl; } } // Function to print digit '1' void print_one() { for (int i=0; i<5; i++) { for (int j=0; j<5; j++) { if (j==2 || (i==1 && j==1) || i==4) cout << '#'; else cout << " "; } cout << endl; } } // Function to print digit '2' void print_two() { for (int i=0; i<5; i++) { for (int j=0; j<5; j++) { if (i==0 || i==2 || i==4 || (i==1 && j==0) || (i==3 && j==4)) cout << '#'; else cout << " "; } cout << endl; } } // Function to print digit '3' void print_three() { for (int i=0; i<5; i++) { for (int j=0; j<5; j++) { if (i==0 || i==2 || i==4 || j==4) cout << '#'; else cout << " "; } cout << endl; } } // Function to print digit '4' void print_four() { for (int i=0; i<5; i++) { for (int j=0; j<5; j++) { if (j==4 || i==2 || (j==0 && (i==0 || i==1))) cout << '#'; else cout << " "; } cout << endl; } } // Function to print digit '5' void print_five() { for (int i=0; i<5; i++) { for (int j=0; j<5; j++) { if (i==0 || i==2 || i==4 || (j==0 && i==1) || (j==4 && i==3)) cout << '#'; else cout << " "; } cout << endl; } } // Function to print digit '6' void print_six() { for (int i=0; i<5; i++) { for (int j=0; j<5; j++) { if (i==0 || i==2 || i==4 || (j==0 && (i==1 || i==3)) || (j==4 && i==3)) cout << '#'; else cout << " "; } cout << endl; } } // Function to print digit '7' void print_seven() { for (int i=0 ; i<5; i++) { for (int j=0 ; j<5; j++) { if (i==0 && (j!=4) || (i==2 && (j==2 || j==4)) || j==3) cout << '#'; else cout << " "; } cout << endl; } } // Function to print digit '8' void print_eight() { for (int i=0; i<5; i++) { for (int j=0; j<5; j++) { if (i==0 || i==2 || i==4 || (j==0 && (i==1 || i==3)) || (j==4 && (i==1 || i==3))) cout << '#'; else cout << " "; } cout << endl; } } // Function to print digit '9' void print_nine() { for (int i=0; i<5; i++) { for (int j=0; j<5; j++) { if ( i==0 || i==2 || j==4 || (i==1 && j==0)) cout << '#'; else cout << " "; } cout << endl; } } // Function to process and print each digit of the number void zoom_digit(int number) { stringstream ss; ss << number; string str = ss.str(); for (int k=0; k<str.length(); k++) { cout << endl; switch(str[k]-'0'){ case 0: print_zero(); continue; case 1: print_one(); continue; case 2: print_two(); continue; case 3: print_three(); continue; case 4: print_four(); continue; case 5: print_five(); continue; case 6: print_six(); continue; case 7: print_seven(); continue; case 8: print_eight(); continue; case 9: print_nine(); continue; } } } // Main function to print Zoom digit int main() { long long number = 2546; zoom_digit(number); return 0; }
The above program produces the following result:
##### # ##### # ##### ##### # ##### # ##### # # # # ##### # # ##### # ##### # # #####
Example of Zoom Digits in Integers Using C++ STL
In this example, we first define a separate function for each digit from 0 to 9, where each function returns a fixed 5X5 pattern represented using a vector
#include<iostream> #include<vector> #include<string> #include<functional> using namespace std; // Each digit printer returns a 5x5 character matrix // vector of string vector<string> zero() { return { "#####", "# #", "# #", "# #", "#####" }; } vector<string> one() { return { " # ", " ## ", " # ", " # ", "#####" }; } vector<string> two() { return { "#####", " #", "#####", "# ", "#####" }; } vector<string> three() { return { "#####", " #", "#####", " #", "#####" }; } vector<string> four() { return { "# #", "# #", "#####", " #", " #" }; } vector<string> five() { return { "#####", "# ", "#####", " #", "#####" }; } vector<string> six() { return { "#####", "# ", "#####", "# #", "#####" }; } vector<string> seven() { return { "#####", " #", " # ", " # ", " # " }; } vector<string> eight() { return { "#####", "# #", "#####", "# #", "#####" }; } vector<string> nine() { return { "#####", "# #", "#####", " #", "#####" }; } // digit printer using vector<string> void zoom_digits(long long number) { vector<function<vector<string>()>> digitMap = { zero, one, two, three, four, five, six, seven, eight, nine }; string digits = to_string(number); vector<vector<string>> bigDigits; // Convert each digit into its 5x5 representation for (char ch : digits) { int d = ch - '0'; bigDigits.push_back(digitMap[d]()); } // Print all digits line by line for (int row = 0; row < 5; ++row) { for (const auto& digit : bigDigits) { // space between digits cout << digit[row] << " "; } cout << endl; } } int main() { // given number long long number = 5293; zoom_digits(number); return 0; }
The above program produces the following result:
##### ##### ##### ##### # # # # # ##### ##### ##### ##### # # # # ##### ##### ##### #####