Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8905831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:29:40+00:00 2026-06-15T02:29:40+00:00

Write C/C++/Java code to convert given number into words. eg:- Input: 1234 Output: One

  • 0

Write C/C++/Java code to convert given number into words.

eg:-
Input:
1234

Output:
One thousand two hundred thirty-four.

Input:
10

Output:
Ten

Does it require a complete switch case for digits 0 to 10.

Adding “teen” after every number name (eg: 14: four “teen”.) from 14 to 19.

And than adding “ty” and the digits name for a number in the range 20 to 99.

And so on.

I think there must be some far better approach for solving this.

C code is preferred.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:29:43+00:00Added an answer on June 15, 2026 at 2:29 am
    #include<iostream>
    using namespace std;
    void expand(int);
    int main()
    {
        int num;
        cout<<"Enter a number : ";
        cin>>num;
        expand(num);
    }
    void expand(int value)
    {
        const char * const ones[20] = {"zero", "one", "two", "three","four","five","six","seven",
        "eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen",
        "eighteen","nineteen"};
        const char * const tens[10] = {"", "ten", "twenty", "thirty","forty","fifty","sixty","seventy",
        "eighty","ninety"};
    
        if(value<0)
        {
            cout<<"minus ";
            expand(-value);
        }
        else if(value>=1000)
        {
            expand(value/1000);
            cout<<" thousand";
            if(value % 1000)
            {
                if(value % 1000 < 100)
                {
                    cout << " and";
                }
                cout << " " ;
                expand(value % 1000);
            }
        }
        else if(value >= 100)
        {
            expand(value / 100);
            cout<<" hundred";
            if(value % 100)
            {
                cout << " and ";
                expand (value % 100);
            }
        }
        else if(value >= 20)
        {
            cout << tens[value / 10];
            if(value % 10)
            {
                cout << " ";
                expand(value % 10);
            }
        }
        else
        {
            cout<<ones[value];
        }
        return;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a java code to read the input XML file and
Any tools to convert C code into Java code? I am interested in converting
i want to convert my input Excel file into the Output XML file. If
so i have to write a java code to : Input a name Format
I use Eclipse to write Java code and use DropBox to sync my code
I want to know if it is possible to write java code in android
I want to write a java code that executes some Linux command: String cmd
I have a problem; I want to write a java code for sending an
I want to write some plugin to analysis Java source code. Which part of
I'm trying to write a simple code in Java to connect to a memcache

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.