C Program to Print Digits of Number in Words

Given a positive number N, we have to print the digits of N in words in Most significant digit(MSD) to least significant digit(LSD) sequence.

For Example

Input Number : 2345
Output : Two Three Four Five

C program to print digits of a number in words

In this program, we first take a positive number as input from user using scanf function. Then we reverse the number as we want to print the most significant digits first(from leftmost digit to rightmost). After reversing, we remove rightmost digit one by one and pass it to "printDigit" function. Function "printDigit" that takes a positive number less than 10 as input and print it words using a switch statement.


void printDigit(int digit);
int main() {
    int reverse = 0, digit, num, mod;
    printf("Enter a positive Integer\n");
    scanf("%d", &num);

    /* reverse the input number */
    while (num > 0) {
        reverse = (reverse * 10) + num%10;
        num /= 10;
    num = reverse;

    while (num > 0) {
        digit = num % 10;
        num = num / 10;
    return 0;

void printDigit(int digit){
 switch (digit) {
        case 0:
                printf("Zero ");
        case 1:
                printf("One ");
        case 2:
                printf("Two ");
        case 3:
                printf("Three ");
        case 4:
                printf("Four ");
        case 5:
                printf("Five ");
        case 6:
                printf("Six ");
        case 7:
                printf("Seven ");
        case 8:
                printf("Eight ");
        case 9:
                printf("Nine ");
Enter a positive Integer
Two Four Zero One
Related Topics
C program to find product of digits of a number using while loop
C program to find sum of least and most significant digits of a number
C program to add digits of a number
C program to count number of digits in an integer
C program to find sum of digits of a number using recursion
C program to reverse a number using recursion
C program to find hcf and lcm of two numbers
C program to check armstrong number
C program to convert string to integer
List of all C programs