Number to Words in C, C++, Java & Python – Code with Explanation & Examples in Short and Simple

   

C Program

#include <stdio.h>
void words(int n){
    char *s[]={"zero","one","two","three","four","five","six","seven","eight","nine"};
    if(n/10) words(n/10);
    printf("%s ",s[n%10]);
}
int main(){
    int n;
    scanf("%d",&n);
    words(n);
    return 0;
}

C Output

Input:  
502 

Output:  
five zero two 


C++ Program

#include <iostream>
using namespace std;
void words(int n){
    string s[]={"zero","one","two","three","four","five","six","seven","eight","nine"};
    if(n/10) words(n/10);
    cout<<s[n%10]<<" ";
}
int main(){
    int n;
    cin>>n;
    words(n);
}

C++ Output

Input:  
907 

Output:  
nine zero seven 


JAVA Program

import java.util.*;
class Main{
    static void words(int n){
        String s[]={"zero","one","two","three","four","five","six","seven","eight","nine"};
        if(n/10>0) words(n/10);
        System.out.print(s[n%10]+" ");
    }
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        words(n);
    }
}

JAVA Output

Input:  
304

Output:  
three zero four 


Python Program

def words(n):
    s=["zero","one","two","three","four","five","six","seven","eight","nine"]
    if n//10: words(n//10)
    print(s[n%10], end=" ")

n=int(input())
words(n)

Python Output

Input:  
128 

Output:  
one two eight 


In-Depth Explanation
Example
If the input number is 502, first 5 is processed, then 0, and lastly 2. The output is "five zero two," which is how we would pronounce the number in English.

Real-Life Analogy
Consider the act of pronouncing a phone number. You wouldn't respond by saying "five hundred and two" when asked for the number, but rather "five zero two." That's what this program does, that same thing — decomposing a number into digits and translating every digit into its word representation.

Why It Matters
The conversion of numbers to words has a great number of practical applications in real life. Banks utilize it while writing cheque amounts in words to prevent fraud, voice assistants convert numbers to words in order to make announcements, and digital systems show textual representations of numbers for easier reading.

Learning Insights
This course educates recursion in a very accessible manner. By calling the same function for n/10 again and again, we strip off the number from left to right without reversing it by hand. It also teaches us the usage of arrays as lookup tables — where every digit is directly mapped to a string.

Interview & Real Project Applications
In interviews, this question is usually asked to check whether you know recursion, array indexing, and formatting input-output. In project work, such logic may be extended for whole sentence conversion like "One hundred and twenty-three" rather than just "one two three," which is helpful in billing applications, form filling, and speech generating applications.

When novice programmers look for assistance in converting a number into words in C, C++, Java, or Python, they usually request brief and 100% functional code with good explanation. This number-to-words code employs recursion for ease and effectiveness, assigns each digit to its word equivalent, and produces outputs in human-readable form. Whether you’re preparing for programming interviews, building a voice assistant, or developing a cheque-writing application, understanding how to break down a number into its digits and map them to words is a fundamental programming skill that improves your ability to manipulate data and format it for users. This makes it a highly searched and practical coding example for both beginners and professionals.