Q:

Write C program to print number in words.

0

Write C program to print number in words.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>

int main()
{
    int n, num = 0;

    //Reading a number from user
    printf("Enter any number to print in words: ");
    scanf("%d", &n);

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

    //print corresponding digit in words till num becomes 0
    while(num != 0)
    {
        switch(num % 10)
        {
            case 0: printf("zero ");
                break;
            case 1: printf("one ");
                break;
            case 2: printf("two ");
                break;
            case 3: printf("three ");
                break;
            case 4: printf("four ");
                break;
            case 5: printf("five ");
                break;
            case 6: printf("six ");
                break;
            case 7: printf("seven ");
                break;
            case 8: printf("eight ");
                break;
            case 9: printf("nine ");
                break;
        }

        num = num / 10;
    }

    return 0;
}

Result:

Enter any number to print in words: 12345

one two three four five 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write C program to find LCM of two numbers... >>
<< Write a C program to check whether a number is pal...