Write a program to convert numbers into words?For ex: 547,as Five Hundred and Forty Seven

Showing Answers 1 - 18 of 18 Answers

kamatchi

  • Nov 6th, 2006
 

Code
  1. span style="color: #0000ff;">"ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE""ELEVEN","TWELVE","THIRTEEN","FOURTEEN","FIFTEEN","SIXTEEN",

  2. "SEVENTEEN","EIGHTEEN","NINTEEN""TEN","TWENTY","THIRTY","FOURTY","FIFTY","SIXTY","SEVENTY",

  3. "EIGHTY","NINTY""ttEnter the number");

  4. scanf("%d""tt""%s THOUSAND"" %s HUNDRED AND "" %s""%s"" %s""ttEnter the small number");

  5. getch();

  6. }

  7.  

  Was this answer useful?  Yes

Sundar A

  • Nov 29th, 2006
 

Gud idea!!! But how will "1003" Work???

abhimanipal

  • Jul 16th, 2009
 

This is not a final answer ...More an algorithm

Suppose we will consider numbers till 9,999 only ...

Array1 --> One,two,three,four,five ......nine
Array2 --> Eleven, Twelve,thirteen,Fourteen.....Nineteen
Array3 --> Twenty,Thirty,Forty,Fifty,Sixty......Ninety
Array4 --> One hundred,two hundred,three hundred,four hundred..... nine hundred
Array5 --> One thousand, two thousand, three thousand .... nine thousand

First check if the number is between 11-20
If yes then print the number
If no then print the last digit from array1 and second last digit from array3.
Similary print the digit in the hundred place from Array 4
Then print the digit in thousands place from Array5

For going beyond this we again use the above technique only....
Also this algorithm prints out the digits in reverse. So to print correct insert in reverse in a linked list. So when the list prints it will print straight.

  Was this answer useful?  Yes

Sameer Habib Khan

  • Dec 17th, 2012
 

Here is Better code that converts number (upto 9 digit) to word

Code
  1. /*

  2.         Author: Sameer Khan

  3.         Date:   17/12/2012

  4.         Program:Number to Word Convertor

  5.  

  6. */java.io.*java.util.*"""""

  7. Enter A Number(Upto 9 Digit): ""

  8. Word: "+word);

  9.                        

  10.                         word="";//reset

  11. "

  12. Do You Want to Continue..?(y/n)""y""Zero"// Get total digits in number

  13. "One""Two""Three""Four""Five""Six""Seven""Eight""Nine""Ten""Eleven""Twelve""Thirteen""Fourteen""Fifteen""Sixteen""Seventeen""Eightteen""Nineteen""Twenty ""Thirty ""Fourty ""Fifty ""Sixty ""Seventy ""Eighty ""Ninety "" Hundred "" Thousand "" Lakh "" Lakhs "" Crore "" Crores "

  Was this answer useful?  Yes

mm

  • Apr 22nd, 2013
 

Code
  1. #include<stdio.h>

  2. #include<conio.h>

  3. " "," one"," two"," three"," four"," five"," six"," seven","eight"," Nine"," ten"," eleven"," twelve"," thirteen"," fourteen","fifteen"," sixteen"," seventeen"," eighteen"," nineteen"" "," "," twenty"," thirty"," forty"," fifty"," sixty","seventy"," eighty"," ninety""Enter any 9 digit no: ");

  4.  scanf("%9ld""Enter numbers greater than 0""crore");

  5.                   pw(((n/100000)%100),"lakh");

  6.                   pw(((n/1000)%100),"thousand");

  7.                   pw(((n/100)%10),"hundred");

  8.                   pw((n%100)," ");

  9.  }

  10.  //getch();"%s %s ""%s ""%s ",ch);

  11. }

Code
  1. #include<stdio.h>

  2. #include<conio.h>

  3. " "," one"," two"," three"," four"," five"," six"," seven","eight"," Nine"," ten"," eleven"," twelve"," thirteen"," fourteen","fifteen"," sixteen"," seventeen"," eighteen"," nineteen"" "," "," twenty"," thirty"," forty"," fifty"," sixty","seventy"," eighty"," ninety""Enter any 9 digit no: ");

  4.  scanf("%9ld""Enter numbers greater than 0""crore");

  5.                   pw(((n/100000)%100),"lakh");

  6.                   pw(((n/1000)%100),"thousand");

  7.                   pw(((n/100)%10),"hundred");

  8.                   pw((n%100)," ");

  9.  }

  10.  //getch();"%s %s ""%s ""%s ",ch);

  11. }

  12.  

  Was this answer useful?  Yes

The following handles up to 32-bit integer values. Not the prettiest code in the world, but it works pretty well.


Sample output:


[fbgo448@n9dvap997]~/prototypes/numbers: ./numbers 1

one

[fbgo448@n9dvap997]~/prototypes/numbers: ./numbers 12

twelve

[fbgo448@n9dvap997]~/prototypes/numbers: ./numbers 123

one hundred and twenty-three

[fbgo448@n9dvap997]~/prototypes/numbers: ./numbers 1234

one thousand, two hundred and thirty-four

[fbgo448@n9dvap997]~/prototypes/numbers: ./numbers 12345

twelve thousand, three hundred and forty-five

[fbgo448@n9dvap997]~/prototypes/numbers: ./numbers 123456

one hundred and twenty-three thousand, four hundred and fifty-six

[fbgo448@n9dvap997]~/prototypes/numbers: ./numbers 1234567

one million, two hundred and thirty-four thousand, five hundred and sixty-seven

[fbgo448@n9dvap997]~/prototypes/numbers: ./numbers -1234567890

minus one billion, two hundred and thirty-four million, five hundred and sixty-seven thousand, eight hundred and ninety

Code
  1. #include <stdio.h>

  2. #include <stdlib.h>

  3. #include <math.h>

  4. "", "one", "two", "three", "four",

  5.     "five", "six", "seven", "eight", "nine""ten", "eleven", "twelve", "thirteen", "fourteen",

  6.     "fifteen", "sixteen", "seventeen", "eighteen", "nineteen""", "", "twenty", "thirty", "forty", "fifty", "sixty",

  7.     "seventy", "eighty", "ninety""", "thousand", "million", "billion"

  8. };

  9.  

  10. /**

  11.  * Return the total number of digits in the value

  12.  *//**

  13.  * Print each century, a group of up to 3 digits

  14.  *

  15.  *    1  => one

  16.  *   12  => twelve

  17.  *  123  => one hundred twenty-three

  18.  */"""%s hundred ""and ""%s%s""-%s ""%s%s ""%s%s ""USAGE: %s <number>\n""minus ""zero"/**

  19.      * Break value into groups of hundreds,

  20.      * such as:

  21.      *

  22.      *       12 =         12

  23.      *      123 =>       123

  24.      *     1234 =>     1 234

  25.      *    12345 =>    12 345

  26.      *   123456 =>   123 456

  27.      *  1234567 => 1 234 567

  28.      *

  29.      * and print each group with the proper

  30.      * magnitude (one million, two hundred and thirty-four

  31.      * thousand, five hundred and sixty-seven for the last

  32.      * example)

  33.      */"""%s", sep );

  34.       sep = ", ""%s"""" and "

  Was this answer useful?  Yes

khalid

  • May 10th, 2014
 

Accept a number from user and display the hundred, teen 9 units in value

  Was this answer useful?  Yes

Chahit

  • Jun 12th, 2014
 

The correct code is following (it works for till user enters max value for int i.e. 2,147,483,647)

Code
  1. /*

  2.  * Program to convert entered number into string

  3.  * */com.orkash.assignment3java.util.Scanner//for taking input number

  4. "

  5.  

  6. Enter the Number (Maximum value that can be entered is 2,147,483,647)"//checking if entered number exceeds maximum integer value

  7. //type casting double number to integer number

  8. //calling splitNumber-it will split complete number in pairs of 3 digits

  9. "Enter smaller value");//asking user to enter a smaller value compared to 2,147,483,647

  10. //function to split complete number into pair of 3 digits each

  11. //splitNumber array-contains the numbers in pair of 3 digits

  12. //splitting number into pair of 3

  13. "zero"//passing each pair of 3 digits to another function

  14. //toWords function will split pair of 3 digits to separate digits

  15. //if the number contained more than 9 digits

  16. "billion,"//if the number contained more than 6 digits & less than 10 digits

  17. "million,""thousand,");//if the number contained more than 3 digits & less than 7 digits

  18.                                 }

  19.                                 }              

  20.         }

  21.         //function that splits number into individual digits

  22. //splitSmallNumber array contains individual digits of number passed to this function

  23. //making temporary copy of the number

  24.                 //logic to split number into its constituent digits

  25. //printing words for each digit

  26. //{     if the digit is greater than zero

  27. //if the digit is at 3rd place or if digit is at (1st place with digit at 2nd place not equal to zero)

  28. "one ""two ""three ""four ""five ""six ""seven ""eight ""nine "//if digit is at 2nd place

  29. //if digit at 2nd place is 0 or 1

  30. "hundred "//if digit at 2nd place is 1 example-213

  31. "eleven ""twelve ""thirteen ""fourteen ""fifteen ""sixteen ""seventeen ""eighteen ""nineteen ""ten "//if digit at 2nd place is not 1

  32. "twenty ""thirty ""forty ""fifty ""sixty ""seventy ""eighty ""ninety "//case 0: System.out.println("hundred ");break;

  33.                                                

  34.                                 }                                                      

  35.                         }                      

  36.                 }

  37.           }

  38.        

  39. }

  Was this answer useful?  Yes

Shridhar

  • Jun 27th, 2014
 

Code
  1. #include<stdio.h>

  2. "enter a 4 digit non negative number  ");    

  3. scanf("%d"" the entered number is :-  ""zero ""one thousand""%s ""two thousand""%s ""three thousand""%s ""four thousand""%s ""five thousand""%s ""six thousand""%s ""seven thousand""%s ""eight thousand""%s ""nine thousand""%s ""one hundred""%s ""two hundred""%s ""three hundred""%s ""four hundred""%s ""five hundred""%s ""six hundred""%s ""seven hundred""%s ""eight hundred""%s ""nine hundred""%s ""%s""%s""%s""%s""%s""%s""%s""%s""%s""%s ""%s ""%s ""%s ""%s ""%s ""%s ""%s "

  Was this answer useful?  Yes

daisy

  • Sep 24th, 2014
 

enter ur no. at field
STDIN Input:

Code
  1. #include <stdio.h>;

  2. "ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE""ELEVEN","TWELVE","THIRTEEN","FOURTEEN","FIFTEEN","SIXTEEN","SEVENTEEN","EIGHTEEN","NINTEEN""TEN","TWENTY","THIRTY","FOURTY","FIFTY","SIXTY","SEVENTY","EIGHTY","NINTY""  Enter the number");

  3. scanf("%d""     ""%s THOUSAND"" %s HUNDRED "" %s""%s"" %s""     Enter the small number");

  4. }

  Was this answer useful?  Yes

naresh sathivilli

  • Oct 29th, 2014
 

Please find the answer in C++ language!
It supports more than one Crore.

Code
  1.  

  2.  

  3. //Naresh Sathivilli

  4.  

  5.  

  6. #include<iostream>

  7. "Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine""Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen""Ten","Twenty","Thirty","Fourty","Fifty","Sixty","Seventy","Eighty","Ninty","Hundred""Thousand""Hundred""Lakh""Lakhs""Crore""Crores"//cout<<"number entry="<<number<<endl;

  8. " "" "" "" "" "" "" "" "" "//cout<<"

  9. "<<number<<endl;

  10.  if(number == 0) return;

  11.  Convert(number);

  12. }

  13.  

  14. int main()

  15. {

  16.    

  17.   Convert(987654326);

  18.  

  19. }

  20.  

  Was this answer useful?  Yes

Code
  1. /***** C program to convert number from 0 to 9999 into word******/

  2. #include<stdio.h>

  3. #include<conio.h>

  4. "one","two","three","four","five","six","seven","eight","nine""eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","ninteen""ten","twenty","thirty","fourty","fifty","sixty","seventy","eighty","ninty""

  5. Enter number:");

  6.         scanf("%d""     num : %d""%s Thousand""%s Hundred and""%s ""%s ""%s""%s""zero""

  7. Enter small number");

  8.         getch();

  9. }


  Was this answer useful?  Yes

aston martin

  • Oct 30th, 2015
 

Guys no one can do in normal bufferedreader?
or in string? so much of jigjag!

  Was this answer useful?  Yes

Narasimhaswamy challa

  • Jun 6th, 2016
 

C code to covert each digits of a number in English word

Convert digits to words in c

Code
  1.  

  2.  

  3. #include<stdio.h>

  4. "Enter any integer: ");

  5.     scanf("%d""zero""one""two""three""four""five""six""seven""eight""nine""%s "


Sample output:

Enter any integer: 23451208
two three four five one two zero eight

  Was this answer useful?  Yes

Shahriar Tasnim

  • Apr 29th, 2017
 

Code
  1. #include<iostream>

  2. "Ten ""Eleven ""Twelve ""Thirteen ""Fourteen ""Fifteen ""Sixteen ""Seventeen ""Eighteen ""Nineteen ""Twenty ""Thirty ""Forty ""Fifty ""Sixty ""Seventy ""Eighty ""Ninety ""Hundred ""Thousand ""Lac ""Million ""Crore ""Thousand ""One ""Two ""Three ""Four ""Five ""Six ""Seven ""Eight ""Nine ""Zero"

  Was this answer useful?  Yes

ARTI SHUKLA

  • Aug 9th, 2018
 

Look the error for 1012....1019......2012......2019.....and so on, CORRECT IT SIR!

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions