Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
208 views
in Technique[技术] by (71.8m points)

Printing a given number in larger size in console using c

PLEASE HELP Where did I make mistake in the following program? It is not giving the expected output. I have found some solutions to this problem but they are using different logic. I want to know what is the problem with the following logic. I did a dry ran according to this logic, I didn't find any problem there. I am really very confused.

# include <stdio.h>
int main()
{
    char zero[5][5] = {
        "#####",
        "#   #",
        "#   #",
        "#   #",
        "#####"
    };
    char one[5][5] = {
        "    #",
        "    #",
        "    #",
        "    #",
        "    #"
    };
    char two[5][5] = {
        "#####",
        "    #",
        "#####",
        "#    ",
        "#####"
    };
    char three[5][5] = {
        "#####",
        "    #",
        "#####",
        "    #",
        "#####"
    };
    char four[5][5] = {
        "#   #",
        "#   #",
        "#####",
        "    #",
        "    #"
    };
    char five[5][5] = {
        "#####",
        "#    ",
        "#####",
        "    #",
        "#####"
    };
    char six[5][5] = {
        "#####",
        "#    ",
        "#####",
        "#   #",
        "#####"
    };
    char seven[5][5] = {
        "#####",
        "    #",
        "    #",
        "    #",
        "    #"
    };
    char eight[5][5] = {
        "#####",
        "#   #",
        "#####",
        "#   #",
        "#####"
    };
    char nine[5][5] = {
        "#####",
        "#   #",
        "#####",
        "    #",
        "#####"
    };

    char userInput[3] = "356";
    int n = 3,i,j;
    for(i=0;i<5;i++)
    {
        for(j=0;j<n;j++)
        {
            switch(userInput[j])
            {
                case '0':
                    printf("%s ",zero[i]);
                    break;
                case '1':
                    printf("%s ",one[i]);
                    break;
                case '2':
                    printf("%s ",two[i]);
                    break;
                case '3':
                    printf("%s ",three[i]);
                    break;
                case '4':
                    printf("%s ",four[i]);
                    break;
                case '5':
                    printf("%s ",five[i]);
                    break;
                case '6':
                    printf("%s ",six[i]);
                    break;
                case '7':
                    printf("%s ",seven[i]);
                    break;
                case '8':
                    printf("%s ",eight[i]);
                    break;
                case '9':
                    printf("%s ",nine[i]);
                    break;
            }
            
        }
        printf("
");
        
    }
}
question from:https://stackoverflow.com/questions/65859628/printing-a-given-number-in-larger-size-in-console-using-c

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Edit: I took John Bodes comment to form an answer.

# include <stdio.h>
int main()
{
    char zero[][6] = {
        "#####",
        "#   #",
        "#   #",
        "#   #",
        "#####"
    };
    char one[][6] = {
        "    #",
        "    #",
        "    #",
        "    #",
        "    #"
    };
    char two[][6] = {
        "#####",
        "    #",
        "#####",
        "#    ",
        "#####"
    };
    char three[][6] = {
        "#####",
        "    #",
        "#####",
        "    #",
        "#####"
    };
    char four[][6] = {
        "#   #",
        "#   #",
        "#####",
        "    #",
        "    #"
    };
    char five[][6] = {
        "#####",
        "#    ",
        "#####",
        "    #",
        "#####"
    };
    char six[][6] = {
        "#####",
        "#    ",
        "#####",
        "#   #",
        "#####"
    };
    char seven[][6] = {
        "#####",
        "    #",
        "    #",
        "    #",
        "    #"
    };
    char eight[][6] = {
        "#####",
        "#   #",
        "#####",
        "#   #",
        "#####"
    };
    char nine[][6] = {
        "#####",
        "#   #",
        "#####",
        "    #",
        "#####"
    };
    //found another spot that's dangerous
    char userInput[] = "356";
    int n = 3,i,j;
    for(i=0;i<5;i++)
    {
        for(j=0;j<n;j++)
        {
            switch(userInput[j])
            {
                case '0':
                    printf("%s ",zero[i]);
                    break;
                case '1':
                    printf("%s ",one[i]);
                    break;
                case '2':
                    printf("%s ",two[i]);
                    break;
                case '3':
                    printf("%s ",three[i]);
                    break;
                case '4':
                    printf("%s ",four[i]);
                    break;
                case '5':
                    printf("%s ",five[i]);
                    break;
                case '6':
                    printf("%s ",six[i]);
                    break;
                case '7':
                    printf("%s ",seven[i]);
                    break;
                case '8':
                    printf("%s ",eight[i]);
                    break;
                case '9':
                    printf("%s ",nine[i]);
                    break;
            }
            
        }
        printf("
");
        
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...