Answer to Question #291988 in C for Squire

Question #291988

Create a program that will take in an input integer number from the user. And will display each digit in word form. However, three digits will instead be shown as an enlarged font. These digits are 2, 4 and 5. These digits will be displayed in an arrangement of asterisks (*). The size of the digits will be based on the digit previous to the enlarged digit. If the first digit fed is an enlarged input, then the default size is 5.



1
Expert's answer
2022-02-01T11:59:52-0500
#include <stdio.h>
#include <math.h>
#include <term.h>


setupterm(NULL, STDOUT_FILENO, NULL);
int main()
{
    int n, num = 0, digits;


    printf("Enter any number to print in words: ");
    scanf_s("%d", &n);


    digits = (int)log10(n);


    while (n != 0)
    {
        num = (num * 10) + (n % 10);
        n /= 10;
    }


    digits = digits - ((int)log10(num));


    while (num != 0)
    {
        switch (num % 10)
        {
        case 0:
            printf("Zero ");
            break;
        case 1:
            printf("One ");
            break;
        case 2:
            putp(enter_bold_mode);
            printf("*Two* ");
            putp(exit_attribute_mode);
            break;
        case 3:
            printf("Three ");
            break;
        case 4:
            putp(enter_bold_mode);
            printf("*Four* ");
            putp(exit_attribute_mode);
            break;
        case 5:
            putp(enter_bold_mode);
            printf("*Five* ");
            putp(exit_attribute_mode);
            break;
        case 6:
            printf("Six ");
            break;
        case 7:
            printf("Seven ");
            break;
        case 8:
            printf("Eight ");
            break;
        case 9:
            printf("Nine ");
            break;
        }


        num /= 10;
    }


    while (digits)
    {
        printf("Zero ");
        digits--;
    }


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS