Open In App

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)


Next Article
Article Tags :
Practice Tags :

Similar Reads