A creative C++ program to Zoom digits of an integer Last Updated : 21 Jun, 2022 Comments Improve Suggest changes Like Article Like Report Write a C (or C++) program to ZOOM (magnify) the digits of an integer. It should take an integer from the user and display each digit of the integer in magnified form using some pattern. Examples: Input : 123 Output : @ @@ @ @ @@@@@ ------------------------------- @@@@ @ @ @ @ @@@@ ------------------------------- @@@@@ @ @@@@@ @ @@@@@ ------------------------------- This creative program takes an integer from the user and print each and every digit of that integer after zooming it. The given number is first converted to string using stringstream. After that, each character (digit) is accessed and put to switch-case structure which ZOOMED each digit and printed in the form of pattern. Below is C++ implementation C // C++ program to zoon digits of an integer #include <bits/stdc++.h> using namespace std; void zoomDigits(int number) { // Converting number to string stringstream ss; ss << number; string str = ss.str(); for (int k=0; k<str.length(); k++) { switch(str[k]-'0') { case 0: for (int i=0; i<5; i++) { for (int j=0; j<5; j++) { if (i==0 || i==4) cout << '@'; else if (j==0 || j==4) cout << '@'; else cout << " "; } cout << endl; } cout << "-------------------------------\n\n"; continue; case 1: for (int i=0; i<5; i++) { for (int j=0; j<5; j++) { if (j==2) cout << '@'; else if ((i==1 && j==1)) cout << '@'; else if (i==4) cout << '@'; else cout << " "; } cout << endl; } cout << "-------------------------------\n\n"; continue; case 2: for (int i=0; i<5; i++) { for (int j=0; j<4; j++) { if (i==0 && j==4) cout << " "; else if (i==0 || i==4) cout << '@'; else if (i==1 && j==0) cout << '@'; else if (i==(4-j)) cout << '@'; else cout << " "; } cout << endl; } cout << "-------------------------------\n\n"; continue; case 3: for (int i=0; i<5; i++) { for (int j=0; j<5; j++) { if (i==0 || i==2 || i==4) cout << '@'; else if (j==4) cout << '@'; else cout << " "; } cout << endl; } cout << "-------------------------------\n\n"; continue; case 4: for (int i=0; i<5; i++) { for (int j=0; j<5; j++) { if (j==4) cout << '@'; else if (i==2) cout << '@'; else if (j==0 && (i==0 || i==1)) cout << '@'; else cout << " "; } cout << endl; } cout << "-------------------------------\n\n"; continue; case 5: for (int i=0; i<5; i++) { for (int j=0; j<5; j++) { if (i==0 || i==2 || i==4) cout << '@'; else if ((j==0 && i==1) || (j==4 && i==3)) cout << '@'; else cout << " "; } cout << endl; } cout << "-------------------------------\n\n"; continue; case 6: for (int i=0; i<5; i++) { for (int j=0; j<5; j++) { if (i==0 || i==2 || i==4) cout << '@'; else if ((j==0 && (i==1 || i==3)) || (j==4 && i==3)) cout << '@'; else cout << " "; } cout << endl; } cout << "-------------------------------\n\n"; continue; case 7: for (int i=0 ; i<5; i++) { for (int j=0 ; j<5; j++) { if (i==0 && (j!=4)) cout << '@'; else if (i==2 && (j==2 || j==4)) cout << '@'; else if (j==3) cout << '@'; else cout << " "; } cout << endl; } cout << "-------------------------------\n\n"; continue; case 8: for (int i=0; i<5; i++) { for (int j=0; j<5; j++) { if (i==0 || i==2 || i==4) cout << '@'; else if ((j==0 && (i==1 || i==3) || (j==4 && (i==1 || i==3)))) cout << '@'; else cout << " "; } cout << endl; } cout << "-------------------------------\n\n"; continue; case 9: for (int i=0; i<5; i++) { for (int j=0; j<5; j++) { if ( i==0 || i==2 || j==4) cout << '@'; else if (i==1 && j==0) cout << '@'; else cout << " "; } cout << endl; } cout << "-------------------------------\n\n"; continue; } } } // Driver code int main() { long long number = 12305; zoomDigits(number); return 0; } Output: @ @@ @ @ @@@@@ ------------------------------- @@@@ @ @ @ @ @@@@ ------------------------------- @@@@@ @ @@@@@ @ @@@@@ ------------------------------- @@@@@ @ @ @ @ @ @ @@@@@ ------------------------------- @@@@@ @ @@@@@ @ @@@@@ ------------------------------- Time complexity : O(n) Auxiliary Space : O(1) Comment More infoAdvertise with us Next Article A creative C++ program to Zoom digits of an integer M MAZHAR IMAM KHAN Improve Article Tags : C++ cpp-puzzle Practice Tags : CPP Similar Reads C++ Program to Convert String to Integer Given a string of digits, the task is to convert the string to an integer. Examples: Input : str = "12345" Output : 12345 Input : str = "876538"; Output : 876538 Input : str = "0028"; Output : 28 CPP // C++ program to convert String into Integer #include <bits/stdc++.h> using namespace std; // 1 min read How to Read and Print an Integer value in C++ The given task is to take an integer as input from the user and print that integer in C++ language. In this article, we will learn how to read and print an integer value. In the below program, the syntax and procedures to take the integer as input from the user is shown in C++ language. Standard Inp 2 min read Input an integer array without spaces in C How to input a large number (a number that cannot be stored even in long long int) without spaces? We need this large number in an integer array such that every array element stores a single digit. Input : 10000000000000000000000000000000000000000000000 We need to read it in an arr[] = {1, 0, 0...., 2 min read Most Critical Mistakes & Tips in Competitive Programming The moment a beginner hears this word, an image pops up in one's mind where students are sitting in a room full of Computers and coding some out of the world stuff, We'll to be honest it's nothing too hard to grasp so we will be proposing tips that help a programmer to level up faster. So let's begi 15+ min read BigInt (BIG INTEGERS) in C++ with Example In C/C++ the number of digits a long long int can have is a maximum of 20. And the question is to store the 22 digit number which is not easy to store in any kind of primitive type. So to deal with this type of problem let's design a new data type which is going to be called BigInt In this article, 15+ min read std::bitset::to_ullong and std::bitset::to_ulong in C++ STL Bitset: A bitset is an array of bool but each Boolean value is not stored separately instead bitset optimizes the space such that each bool takes 1 bit space only, so space taken by bitset bs is less than that of bool bs[N] and vector bs(N). However, a limitation of bitset is, N must be known at com 2 min read Print individual digits as words without using if or switch Given a number, print words for individual digits. It is not allowed to use if or switch.Examples: Input: n = 123 Output: One Two Three Input: n = 350 Output: Three Five Zero We strongly recommend you to minimize your browser and try this yourself first. The idea is to use an array of strings to sto 5 min read std::oct , std::dec and std::hex in C++ This function is used to set the base to octal, decimal or hexadecimal. It sets the basefield format flag for the str stream to the specified base std::oct : When basefield is set to octal, integer values inserted into the stream are expressed in octal base (i.e., radix 8). For input streams, extrac 2 min read std::numeric_limits<T>::digits in C++ with Example The std::numeric_limits::digits function in C++ STL is present in the <limits> header file. The std::numeric_limits::digits function is used to find the number of radix digits that the data type can represent without loss of precision. Header File: #include<limits> Template: static const 1 min read C++ Program For Radix Sort Radix Sort is a sorting technique in which we sort the elements by processing each and every digit of that element. It is not a comparison-based sorting algorithm which means we do not compare the elements in a radix sort in order to sort them. Here, we apply counting sort to every digit of an eleme 5 min read Like