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

Showing Answers 1 - 52 of 52 Answers

kamatchi

  • Nov 6th, 2006
 

Code
  1.  

  2. void main()

  3. {

  4. char a[10][10]={"ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE"};

  5. char b[10][10]={"ELEVEN","TWELVE","THIRTEEN","FOURTEEN","FIFTEEN","SIXTEEN",

  6. "SEVENTEEN","EIGHTEEN","NINTEEN"};

  7. char c[10][10]={"TEN","TWENTY","THIRTY","FOURTY","FIFTY","SIXTY","SEVENTY",

  8. "EIGHTY","NINTY"};

  9. int no,t;

  10. clrscr();

  11. printf("ttEnter the number");

  12. scanf("%d",&no);

  13. printf("tt");

  14. if(no<9999)

  15. {

  16.  if(no>1000)

  17.  {

  18.   t=no/1000;

  19.   no=no%1000;

  20.   printf("%s THOUSAND",a[t-1]);

  21.  }

  22.  if(no>100)

  23.  {

  24.   t=no/100;

  25.   no=no%100;

  26.   printf(" %s HUNDRED AND ",a[t-1]);

  27.  }

  28.  if(no>=10 && no<20)

  29.  {

  30.   t=no/10;

  31.   printf(" %s",b[t-1]);

  32.  }

  33.  if(no>19 && no<=100)

  34.  {

  35.   t=no/10;

  36.   no=no%10;

  37.   printf("%s",c[t-1]);

  38.  }

  39.  if(no<10)

  40.  {

  41.   printf(" %s",a[no-1]);

  42.  }

  43. }

  44. else

  45. printf("ttEnter the small number");

  46. getch();

  47. }

  48.  

  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

Code
  1. #include<stdio.h>

  2. main()

  3. {

  4. int n,temp,rev=0;

  5. scanf("%d",&n);

  6. temp=n;

  7. while(n>0)

  8. {

  9. rev=(rev*10)+(n%10);

  10. n=n/10;

  11. }

  12. printf("%d",rev);

  13. while(rev>0)

  14. {

  15. switch(rev%10)

  16. {

  17. case 1:printf("one ");

  18.         break;

  19. case 2:printf("two ");

  20.         break;

  21. case 3:printf("three ");

  22.         break;

  23. case 4:printf("four ");

  24.         break;

  25. case 5:printf("five ");

  26.         break;

  27. case 6:printf("six ");

  28.         break;

  29. case 7:printf("seven ");

  30.         break;

  31. case 8:printf("eight ");

  32.         break;

  33. case 9:printf("nine ");

  34.         break;

  35. case 0:printf("zero ");

  36.         break;

  37. }

  38. rev=rev/10;

  39. }

  40. while(temp%10==0)

  41. {

  42. printf("zero ");

  43. temp=temp/10;

  44. }

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. */

  7.  

  8.  

  9. import java.io.*;

  10. import java.util.*;

  11.  

  12. public class NumberToWord

  13. {

  14.        

  15.         static String word="";

  16.         public static void main(String...args) throws IOException

  17.         {

  18.        

  19.                 String response="";

  20.                 do{

  21.                         BufferedReader br =new BufferedReader(new InputStreamReader(System.in));

  22.                

  23.                         System.out.println("

  24. Enter A Number(Upto 9 Digit): ");

  25.                         String input=br.readLine();

  26.                        

  27.                         Convert(input);

  28.                         System.out.println("

  29. Word: "+word);

  30.                        

  31.                         word="";//reset

  32.                        

  33.                         System.out.println("

  34. Do You Want to Continue..?(y/n)");

  35.                         response=br.readLine();

  36.                

  37.                 }while(response.equalsIgnoreCase("y"));

  38.                

  39.        

  40.         }

  41.        

  42.         public static void Convert(String input)

  43.         {

  44.                        

  45.                 int number=Integer.parseInt(input);

  46.                 if(number==0)

  47.                 {

  48.                         word="Zero";

  49.                         return;

  50.                 }

  51.                 int d=0;

  52.                

  53.                 int len=input.length(); // Get total digits in number

  54.                         switch(len)

  55.                         {

  56.                                 case 1:

  57.                                                 ones(number);

  58.                                                 break;

  59.                                 case 2:

  60.                                                 twos(number);

  61.                                                 break;                 

  62.                                 case 3:

  63.                                                 threes(number);        

  64.                                                 break;

  65.                                 case 4:

  66.                                                 fours(number);

  67.                                                 break; 

  68.                                 case 5:

  69.                                                 fives(number);

  70.                                                 break;

  71.                                 case 6:

  72.                                                 sixs(number);

  73.                                                 break;

  74.                                 case 7:

  75.                                                 sevens(number);

  76.                                                 break;

  77.                                 case 8:

  78.                                                 eights(number);

  79.                                                 break;

  80.                                 case 9:

  81.                                                 nines(number);

  82.                                                 break;                                                                                 

  83.                                                        

  84.                         }

  85.                

  86.                

  87.        

  88.        

  89.                        

  90.         }

  91.  

  92.         public static void ones(int c)

  93.         {

  94.                         switch(c)

  95.                         {

  96.                                 case 1: word+="One";

  97.                                                 break;

  98.                                 case 2: word+="Two";

  99.                                                 break;                 

  100.                                 case 3:word+="Three";  

  101.                                                 break;

  102.                                 case 4:word+="Four";   

  103.                                                 break;

  104.                                 case 5:word+="Five";   

  105.                                                 break;                                         

  106.                                 case 6:word+="Six";    

  107.                                                 break;

  108.                                 case 7:word+="Seven";  

  109.                                                 break;

  110.                                 case 8:word+="Eight";  

  111.                                                 break;

  112.                                 case 9:word+="Nine";   

  113.                                                 break;                                                                                                 

  114.                         }

  115.        

  116.         }

  117.  

  118.         public static void twos(int c)

  119.         {

  120.                         if(c>9&&c<20)

  121.                         {

  122.                            switch(c)

  123.                            {

  124.                                

  125.                                 case 10: word+="Ten";

  126.                                                 break;

  127.                                 case 11: word+="Eleven";

  128.                                                 break;

  129.                                 case 12: word+="Twelve";

  130.                                                 break;                 

  131.                                 case 13:word+="Thirteen";              

  132.                                                 break;

  133.                                 case 14:word+="Fourteen";              

  134.                                                 break;

  135.                                 case 15:word+="Fifteen";               

  136.                                                 break;

  137.                                 case 16:word+="Sixteen";               

  138.                                                 break;

  139.                                 case 17:word+="Seventeen";             

  140.                                                 break;

  141.                                 case 18:word+="Eightteen";             

  142.                                                 break;

  143.                                 case 19:word+="Nineteen";              

  144.                                                 break;

  145.                                        

  146.                           }

  147.                        

  148.                         }

  149.                         else

  150.                         {

  151.                        

  152.                            if(c>=20&&c<30)

  153.                                 {

  154.                                         word=word+"Twenty ";

  155.                                         ones(c%10);    

  156.                                        

  157.                                 }

  158.                                 if(c>=30&&c<40)

  159.                                 {

  160.                                         word=word+"Thirty ";

  161.                                         ones(c%10);    

  162.                                        

  163.                                 }

  164.                                 if(c>=40&&c<50)

  165.                                 {

  166.                                         word=word+"Fourty ";

  167.                                         ones(c%10);    

  168.                                        

  169.                                 }

  170.                                 if(c>=50&&c<60)

  171.                                 {

  172.                                         word=word+"Fifty ";

  173.                                         ones(c%10);    

  174.                                        

  175.                                 }

  176.                                 if(c>=60&&c<70)

  177.                                 {

  178.                                         word=word+"Sixty ";

  179.                                         ones(c%10);    

  180.                                        

  181.                                 }

  182.                                 if(c>=70&&c<80)

  183.                                 {

  184.                                         word=word+"Seventy ";

  185.                                         ones(c%10);    

  186.                                        

  187.                                 }

  188.                                 if(c>=80&&c<90)

  189.                                 {

  190.                                         word=word+"Eighty ";

  191.                                         ones(c%10);    

  192.                                        

  193.                                 }

  194.                                 if(c>=90&&c<100)

  195.                                 {

  196.                                         word=word+"Ninety ";

  197.                                         ones(c%10);    

  198.                                        

  199.                                 }                              

  200.                

  201.                            

  202.                         }  

  203.        

  204.         }

  205.        

  206.         public static void threes(int c)

  207.         {

  208.                         if(c!=0)

  209.                         {      

  210.                                 ones(c/100);

  211.                                 word=word+" Hundred ";

  212.                                 twos(c%100);

  213.                         }              

  214.         }

  215.  

  216.         public static void fours(int c)

  217.         {

  218.                        

  219.                         ones(c/1000);

  220.                         c=c%1000;

  221.                         word=word+" Thousand ";

  222.                         threes(c%1000);

  223.                                

  224.         }

  225.        

  226.         public static void fives(int c)

  227.         {

  228.                 twos(c/1000);

  229.                 fours(c%1000);

  230.                

  231.                

  232.         }

  233.        

  234.         public static void sixs(int c)

  235.         {

  236.                 ones(c/100000);

  237.                 word=word+" Lakh ";

  238.                 if((c%100000)!=0)

  239.                         fives(c%100000);

  240.                

  241.                

  242.         }

  243.        

  244.         public static void sevens(int c)

  245.         {

  246.                 twos(c/100000);

  247.                 word=word+" Lakhs ";

  248.                 if((c%100000)!=0)

  249.                         fives(c%100000);

  250.         }

  251.        

  252.         public static void eights(int c)

  253.         {

  254.                 ones(c/10000000);

  255.                 word=word+" Crore ";

  256.                 if((c%100000)!=0)

  257.                         sevens(c%10000000);    

  258.        

  259.         }

  260.        

  261.         public static void nines(int c)

  262.         {

  263.                 twos(c/10000000);

  264.                 word=word+" Crores ";

  265.                 if((c%100000)!=0)

  266.                         sevens(c%10000000);    

  267.        

  268.         }

  269.                  

  270.  

  271. }

  Was this answer useful?  Yes

mm

  • Apr 22nd, 2013
 

Code
  1. #include<stdio.h>

  2. #include<conio.h>

  3. void pw(long,char[]);

  4. char *one[]={" "," one"," two"," three"," four"," five"," six"," seven","eight"," Nine"," ten"," eleven"," twelve"," thirteen"," fourteen","fifteen"," sixteen"," seventeen"," eighteen"," nineteen"};

  5. char *ten[]={" "," "," twenty"," thirty"," forty"," fifty"," sixty","seventy"," eighty"," ninety"};

  6. int main()

  7. {

  8.  long n;

  9. clrscr();

  10.  printf("Enter any 9 digit no: ");

  11.  scanf("%9ld",&n);

  12.  

  13.  if(n<=0)

  14.                 printf("Enter numbers greater than 0");

  15.  else

  16.  {

  17.                   pw((n/10000000),"crore");

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

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

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

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

  22.  }

  23.  //getch();

  24.  return 0;

  25. }

  26. void pw(long n,char ch[])

  27. {

  28.  (n>19)?printf("%s %s ",ten[n/10],one[n%10]):printf("%s ",one[n]);

  29.  if(n)printf("%s ",ch);

  30. }

Code
  1. #include<stdio.h>

  2. #include<conio.h>

  3. void pw(long,char[]);

  4. char *one[]={" "," one"," two"," three"," four"," five"," six"," seven","eight"," Nine"," ten"," eleven"," twelve"," thirteen"," fourteen","fifteen"," sixteen"," seventeen"," eighteen"," nineteen"};

  5. char *ten[]={" "," "," twenty"," thirty"," forty"," fifty"," sixty","seventy"," eighty"," ninety"};

  6.  

  7.  

  8. int main()

  9. {

  10.  long n;

  11. clrscr();

  12.  printf("Enter any 9 digit no: ");

  13.  scanf("%9ld",&n);

  14.  

  15.  if(n<=0)

  16.                 printf("Enter numbers greater than 0");

  17.  else

  18.  {

  19.                   pw((n/10000000),"crore");

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

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

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

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

  24.  }

  25.  //getch();

  26.  return 0;

  27. }

  28.  

  29.  

  30. void pw(long n,char ch[])

  31. {

  32.  (n>19)?printf("%s %s ",ten[n/10],one[n%10]):printf("%s ",one[n]);

  33.  if(n)printf("%s ",ch);

  34. }

  35.  

  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.  

  5. static char *units[] = {

  6.     "", "one", "two", "three", "four",

  7.     "five", "six", "seven", "eight", "nine"

  8. };

  9.  

  10. static char *teens[] = {

  11.     "ten", "eleven", "twelve", "thirteen", "fourteen",

  12.     "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"

  13. };

  14.  

  15. static char *decades[] = {

  16.     "", "", "twenty", "thirty", "forty", "fifty", "sixty",

  17.     "seventy", "eighty", "ninety"

  18. };

  19.  

  20. static char *magnitudes[] = {

  21.     "", "thousand", "million", "billion"

  22. };

  23.  

  24. /**

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

  26.  */

  27. int getDigits( long val )

  28. {

  29.    return (int) (floor( log10( (double) abs( val )))) + 1;

  30. }

  31.  

  32. /**

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

  34.  *

  35.  *    1  => one

  36.  *   12  => twelve

  37.  *  123  => one hundred twenty-three

  38.  */

  39. void printCentury( int val )

  40. {

  41.   char *join = "";

  42.   if ( val > 99 )

  43.   {

  44.     int cent = val / 100;

  45.     printf( "%s hundred ", units[cent] );

  46.     val -= cent * 100;

  47.     if ( val > 0 )

  48.       join = "and ";

  49.   }

  50.  

  51.   if ( val > 19 )

  52.   {

  53.     printf( "%s%s", join, decades[val / 10] );

  54.     if ( val % 10 > 0 )

  55.       printf( "-%s ", units[val % 10] );

  56.     else

  57.       putchar(   );

  58.   }

  59.   else if ( val >= 10 )

  60.   {

  61.     printf( "%s%s ", join, teens[val % 10] );

  62.   }

  63.   else if ( val > 0 )

  64.   {

  65.     printf( "%s%s ", join, units[val] );

  66.   }

  67. }

  68.  

  69. int main( int argc, char **argv )

  70. {

  71.   long val = 0;

  72.  

  73.   if ( argc > 1 )

  74.   {

  75.     val = strtol( argv[1], NULL, 10 );

  76.   }

  77.   else

  78.   {

  79.     fprintf( stderr, "USAGE: %s <number>\n", argv[0] );

  80.     return 0;

  81.   }

  82.  

  83.   if ( val < 0 )

  84.   {

  85.     printf( "minus " );

  86.     val = -val;

  87.   }

  88.  

  89.   if ( val == 0 )

  90.     printf( "zero" );

  91.   else

  92.   {

  93.     /**

  94.      * Break value into groups of hundreds,

  95.      * such as:

  96.      *

  97.      *       12 =         12

  98.      *      123 =>       123

  99.      *     1234 =>     1 234

  100.      *    12345 =>    12 345

  101.      *   123456 =>   123 456

  102.      *  1234567 => 1 234 567

  103.      *

  104.      * and print each group with the proper

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

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

  107.      * example)

  108.      */

  109.     char *sep = "";

  110.     while ( val > 100L )

  111.     {

  112.       int digits = getDigits( val );

  113.       int mag = (digits - 1) / 3;

  114.       long order = (long) ( pow (10.0, 3 * mag ));

  115.       long cent = val / order;

  116.       printf( "%s", sep );

  117.       sep = ", ";

  118.       printCentury( (int) cent );

  119.       printf( "%s", magnitudes[mag] );

  120.       val -= cent * order;

  121.     }

  122.     if ( val > 0 && sep != "" )

  123.       printf( " and " );

  124.     printCentury( val );

  125.   }

  126.   putchar(\n);

  127.   return 0;

  128. }

  129.  

  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.  * */

  4.  

  5. package com.orkash.assignment3;

  6.  

  7. import java.util.Scanner;

  8.  

  9. public class NumberToWords {

  10.         public static void main(String[] args)

  11.         {

  12.                 double num;//for taking input number

  13.                 Scanner obj=new Scanner(System.in);

  14.                 do

  15.                 {

  16.                         System.out.println("

  17.  

  18. Enter the Number (Maximum value that can be entered is 2,147,483,647)");

  19.                         num=obj.nextDouble();

  20.                         if(num<=2147483647)//checking if entered number exceeds maximum integer value

  21.                         {

  22.                                 int number=(int)num;//type casting double number to integer number

  23.                                 splitNumber(number);//calling splitNumber-it will split complete number in pairs of 3 digits

  24.                         }

  25.                         else

  26.                                 System.out.println("Enter smaller value");//asking user to enter a smaller value compared to 2,147,483,647

  27.                 }while(num>2147483647);

  28.         }

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

  30.         public static void splitNumber(int number)

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

  32.                 int splitNumber[]=new int[4],temp=number,i=0,index;

  33.                 //splitting number into pair of 3

  34.                 if(temp==0)

  35.                         System.out.println("zero");

  36.                 while(temp!=0)

  37.                 {

  38.                         splitNumber[i++]=temp%1000;

  39.                         temp/=1000;

  40.                 }

  41.                 //passing each pair of 3 digits to another function

  42.                 for(int j=i-1;j>-1;j--)

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

  44.                         if(splitNumber[j]!=0)

  45.                                 {toWords(splitNumber[j]);

  46.                         if(j==3)//if the number contained more than 9 digits

  47.                                 System.out.print("billion,");

  48.                         else if(j==2)//if the number contained more than 6 digits & less than 10 digits

  49.                                 System.out.print("million,");

  50.                         else if(j==1)

  51.                                 System.out.print("thousand,");//if the number contained more than 3 digits & less than 7 digits

  52.                                 }

  53.                                 }              

  54.         }

  55.         //function that splits number into individual digits

  56.         public static void toWords(int number)

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

  58.         {       int splitSmallNumber[]=new int[3],i=0,j;

  59.                 int temp=number;//making temporary copy of the number

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

  61.                

  62.                 while(temp!=0)

  63.                 {

  64.                         splitSmallNumber[i++]=temp%10;

  65.                         temp/=10;

  66.                 }

  67.                 //printing words for each digit

  68.                 for(j=i-1;j>-1;j--)

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

  70.                         if(splitSmallNumber[j]>=0)

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

  72.                         {       if(j==2||(j==0 && (splitSmallNumber[1]!=1)))

  73.                                 {

  74.                                         switch(splitSmallNumber[j])

  75.                                         {

  76.                                        

  77.                                                 case 1:System.out.print("one ");break;

  78.                                                 case 2:System.out.print("two ");break;

  79.                                                 case 3:System.out.print("three ");break;

  80.                                                 case 4:System.out.print("four ");break;

  81.                                                 case 5:System.out.print("five ");break;

  82.                                                 case 6:System.out.print("six ");break;

  83.                                                 case 7:System.out.print("seven ");break;

  84.                                                 case 8:System.out.print("eight ");break;

  85.                                                 case 9:System.out.print("nine ");break;

  86.                                                

  87.                                 }

  88.                                        

  89.                         }

  90.                         //if digit is at 2nd place

  91.                         if(j==1)

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

  93.                                         if(((splitSmallNumber[j]==0)||(splitSmallNumber[j]==1))&& splitSmallNumber[2]!=0 )

  94.                                         System.out.print("hundred ");

  95.                                 switch(splitSmallNumber[1])

  96.                                 {       case 1://if digit at 2nd place is 1 example-213

  97.                                                         switch(splitSmallNumber[0])

  98.                                                         {

  99.                                                         case 1:System.out.print("eleven ");break;

  100.                                                         case 2:System.out.print("twelve ");break;

  101.                                                         case 3:System.out.print("thirteen ");break;

  102.                                                         case 4:System.out.print("fourteen ");break;

  103.                                                         case 5:System.out.print("fifteen ");break;

  104.                                                         case 6:System.out.print("sixteen ");break;

  105.                                                         case 7:System.out.print("seventeen ");break;

  106.                                                         case 8:System.out.print("eighteen ");break;

  107.                                                         case 9:System.out.print("nineteen ");break;

  108.                                                         case 0:System.out.print("ten ");break;

  109.                                                         }break;

  110.                                                         //if digit at 2nd place is not 1

  111.                                                 case 2:System.out.print("twenty ");break;

  112.                                                 case 3:System.out.print("thirty ");break;

  113.                                                 case 4:System.out.print("forty ");break;

  114.                                                 case 5:System.out.print("fifty ");break;

  115.                                                 case 6:System.out.print("sixty ");break;

  116.                                                 case 7:System.out.print("seventy ");break;

  117.                                                 case 8:System.out.print("eighty ");break;

  118.                                                 case 9:System.out.print("ninety ");break;

  119.                                                 //case 0:       System.out.println("hundred ");break;

  120.                                                

  121.                                 }                                                      

  122.                         }                      

  123.                 }

  124.           }

  125.        

  126. }

  Was this answer useful?  Yes

Shridhar

  • Jun 27th, 2014
 

Code
  1. #include<stdio.h>

  2. main() {        int n,u,t,h,th;            

  3. jamkhandi: printf("enter a 4 digit non negative number  ");    

  4. scanf("%d",&n);    

  5.  if(n<0) goto jamkhandi;    

  6.   printf(" the entered number is :-  ");    

  7.  if(n==0)printf("zero ");    

  8. else {          

  9. u=n%10;        

  10. n=n-u;    

  11.         t=n%100; t=t/10;        

  12. h=n%1000;

  13. h=h/100;        

  14. th=n%10000; th=th/1000;         }        

  15. switch(th)    {         case 1: {                    

  16. char th1[100]="one thousand";                        

  17. printf("%s ",th1);break;             }            

  18.  case 2: {                 

  19. char th1[100]="two thousand";                        

  20. printf("%s ",th1);break;             }            

  21. case 3: {                    

  22. char th1[100]="three thousand";                      

  23. printf("%s ",th1);break;             }            

  24. case 4: {                    

  25. char th1[100]="four thousand";                       

  26. printf("%s ",th1);break;             }                          

  27. case 5: {                  

  28.  char th1[100]="five thousand";                      

  29. printf("%s ",th1);break;             }            

  30. case 6: {                    

  31. char th1[100]="six thousand";                        

  32. printf("%s ",th1);break;             }            

  33. case 7: {                  

  34.  char th1[100]="seven thousand";                   

  35.  printf("%s ",th1);break;             }            

  36. case 8: {                  

  37.  char th1[100]="eight thousand";                     

  38. printf("%s ",th1);break;             }            

  39. case 9: {                    

  40. char th1[100]="nine thousand";                       

  41. printf("%s ",th1);break;             }    }  

  42. switch(h)    {          case 1: {                    

  43. char h1[100]="one hundred";                  

  44. printf("%s ",h1);break;             }            

  45. case 2: {                    

  46. char h1[100]="two hundred";                  

  47. printf("%s ",h1);break;             }            

  48. case 3: {                    

  49. char h1[100]="three hundred";                        

  50. printf("%s ",h1);break;             }            

  51. case 4: {                  

  52.  char h1[100]="four hundred";                        

  53. printf("%s ",h1);break;             }                        

  54.  case 5: {                   

  55. char h1[100]="five hundred";                         

  56. printf("%s ",h1);break;             }            

  57.  case 6: {                 

  58.  char h1[100]="six hundred";                       

  59.  printf("%s ",h1);break;             }          

  60.   case 7: {                  char h1[100]="seven hundred";                 

  61.  printf("%s ",h1);break;             }          

  62.   case 8: {                  char h1[100]="eight hundred";               

  63.    printf("%s ",h1);break;             }          

  64.   case 9: {                  char h1[100]="nine hundred";                

  65.   printf("%s ",h1);break;             }    }    

  66.   switch(t)     {          case 1:             

  67.  { if(u==1)              {                     

  68. char t1[100]={e,l,e,v,e,n,};

  69.         printf("%s",t1);        

  70. break;         }

  71.          if(u==2)                {                     

  72. char t1[100]={t,w,e,l,v,e,};        

  73.  printf("%s",t1);       break;         }  

  74.        if(u==3)                  {                     

  75. char t1[100]={t,h,i,r,t,e,e,n,};      

  76.   printf("%s",t1);      

  77. break;    

  78.     }         if(u==4)         

  79.  {                     

  80. char t1[100]={f,o,u,r,t,e,e,n,};    

  81.     printf("%s",t1);            

  82. break;         }      

  83.    if(u==5)              {                     

  84. char t1[100]={f,i,f,t,e,e,n,};      

  85.   printf("%s",t1);      

  86. break;      

  87.    }      

  88.   if(u==6)             

  89.  {                     

  90. char t1[100]={s,i,x,t,e,e,n,};  

  91.       printf("%s",t1);          

  92. break;         }    

  93.      if(u==7)            {                     

  94. char t1[100]={s,e,v,e,n,t,e,e,n,};        

  95.  printf("%s",t1);       break;         }    

  96.      if(u==8)            {                     

  97. char t1[100]={e,i,g,h,t,e,e,n,};        

  98.  printf("%s",t1);       break;         }      

  99.   if(u==9)               {                     

  100. char t1[100]={n,i,n,t,e,e,n,};        

  101.  printf("%s",t1);    

  102.         break;         }         if(u==0)      

  103.   {        

  104.         char t1[100]={t,e,n,};          

  105. puts(t1);        

  106.         break;      }            }             

  107.  case 2: {                     

  108. char t1[100]={t,w,e,n,t,y,};    

  109.                 printf("%s ",t1);                      

  110. break;           }               

  111.  case 3: {               

  112.         char t1[100]={t,h,i,r,t,y,};           

  113.  printf("%s ",t1);                             

  114. break;           }                               

  115.  case 4: {               

  116.         char t1[100]={f,o,r,t,y,};                     

  117. printf("%s ",t1);                

  118.         break;           }               

  119.  case 5: {             

  120.         char t1[100]={f,i,f,t,y,};                     

  121. printf("%s ",t1);                      

  122. break;         

  123.  }               

  124.  case 6: {                     

  125. char t1[100]={s,i,x,t,y,};                     

  126. printf("%s ",t1);                      

  127. break;           }               

  128.  case 7: {                     

  129. char t1[100]={s,e,v,e,n,t,y,};                 

  130. printf("%s ",t1);                      

  131. break;           }               

  132.  

  133. case 8: {                      

  134. char t1[100]={e,i,g,h,t,y,};                   

  135. printf("%s ",t1);                      

  136. break;           }               

  137.  

  138. case 9: {                      

  139. char t1[100]={n,i,n,e,t,y,};                   

  140. printf("%s ",t1);                                              

  141. break;           }                 }  

  142.  if(t!=1)    {         

  143. switch(u)    {         

  144.  case  1: {            

  145.   char u1[100]={o,n,e,};               

  146.  puts(u1);               

  147. break;                   }  

  148.          case 2:  {      

  149.  char u1[100]={t,w,o,};                

  150.  puts(u1);             

  151.  break;                  }                             

  152. case 3:

  153.  {         char u1[100]={t,h,r,e,e,};    

  154.        puts(u1);               

  155.   break;                 }                    

  156.    case 4:  {    

  157.  char u1[100]={f,o,u,r,};              

  158.  puts(u1);             

  159.   break;             

  160.     }                    case 5:  {      

  161.  char u1[100]={f,i,v,e,};              

  162.  puts(u1);         

  163.      break;              }               

  164. case 6:  {         char u1[100]={s,i,x,};              

  165.  puts(u1);               

  166. break;                   }             

  167.  case 7:  {        

  168. char u1[100]={s,e,v,e,n,};             

  169.  puts(u1);           

  170.     break;               }             

  171.  case 8:  {      

  172.  char u1[100]={e,i,g,h,t,};            

  173.   puts(u1);            

  174.  break;                  }           

  175.     case 9:  {    

  176.  char u1[100]={n,i,n,e,};      

  177.          puts(u1);               

  178. break;                   }       }    }        

  179. getch(); }

  180.  </stdio.h>

  Was this answer useful?  Yes

daisy

  • Sep 24th, 2014
 

enter ur no. at field
STDIN Input:

Code
  1. #include <stdio.h>;

  2.  

  3. void main()

  4. {char a[10][10]={"ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE"};

  5. char b[10][10]={"ELEVEN","TWELVE","THIRTEEN","FOURTEEN","FIFTEEN","SIXTEEN","SEVENTEEN","EIGHTEEN","NINTEEN"};

  6. char c[10][10]={"TEN","TWENTY","THIRTY","FOURTY","FIFTY","SIXTY","SEVENTY","EIGHTY","NINTY"};

  7. int no,t;

  8. printf("        Enter the number");

  9. scanf("%d",&no);

  10. printf("        ");

  11. if(no<9999)

  12.   { if(no>=1000)

  13.      {  t=no/1000;

  14.         no=no%1000;  

  15.         printf("%s THOUSAND",a[t-1]); }

  16.     if(no>=100)

  17.      {  t=no/100;  

  18.         no=no%100;  

  19.         printf(" %s HUNDRED ",a[t-1]); }

  20.     if(no>=10 && no<20)

  21.      {  t=no/10;  

  22.         printf(" %s",b[t-1]); }

  23.     if(no>19 && no<=100)

  24.      {  t=no/10;  

  25.         no=no%10;  

  26.         printf("%s",c[t-1]); }

  27.     if(no<10)

  28.      {  printf(" %s",a[no-1]); }

  29.   }

  30. else

  31.   printf("      Enter the small number");

  32. }

  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.  

  8. using namespace std;

  9. const char *Digits []      = {"Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine"};

  10. const char *BelowTwenty[]  = {"Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"};

  11. const char *BelowHundred[] = {"Ten","Twenty","Thirty","Fourty","Fifty","Sixty","Seventy","Eighty","Ninty","Hundred"};

  12. const char *Thousand       = "Thousand";

  13. const char *Hundred        = "Hundred";

  14. const char *Lakh           = "Lakh";

  15. const char *Lakhs          = "Lakhs";

  16. const char *Crore          = "Crore";

  17. const char *Crores         = "Crores";

  18.  

  19. void Convert(long number)

  20. {

  21.   //cout<<"number entry="<<number<<endl;

  22.   if(number >= 10000000)

  23.   {

  24.     Convert(number / 10000000);

  25.     if((number /  10000000) > 1)

  26.       cout<<Crores<<" ";

  27.     else

  28.       cout<<Crore<<" ";

  29.  

  30.     number =number %  10000000;

  31.   }

  32.   else if(number < 10000000 && number >= 100000)

  33.   {

  34.     Convert(number / 100000);

  35.     if((number /  100000) > 1)

  36.       cout<<Lakhs<<" ";

  37.     else

  38.       cout<<Lakh<<" ";

  39.  

  40.     number =number %  100000;

  41.   }

  42.   else if(number < 100000 && number >= 1000)

  43.   {

  44.     Convert(number / 1000);

  45.     number =number %  1000;

  46.     cout<<Thousand<<" ";

  47.   }

  48.   else if(number < 1000 && number > 100)

  49.   {

  50.     Convert(number / 100);

  51.     number =number %  100;

  52.     cout<<Hundred<<" ";

  53.   }

  54.   else if(number < 10)

  55.   {

  56.     cout<<*(Digits+(number))<<" ";

  57.     return;

  58.   }

  59.   else if(number > 10 and number < 20)

  60.   {

  61.     cout<<*(BelowTwenty+(number-11))<<" ";

  62.     return;

  63.   }

  64.   else if(number <= 100)

  65.   {

  66.     cout<<*(BelowHundred+(number / 10)-1)<<" ";

  67.     if(number == 100) return;

  68.     number %= 10;

  69.   }

  70.   else

  71.   {

  72.     return;

  73.   }

  74.   //cout<<"

  75. number exit="<<number<<endl;

  76.  if(number == 0) return;

  77.  Convert(number);

  78. }

  79.  

  80. int main()

  81. {

  82.    

  83.   Convert(987654326);

  84.  

  85. }

  86.  

  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. void main()

  5. {

  6.         char a[10][10]={"one","two","three","four","five","six","seven","eight","nine"};

  7.         char b[10][10]={"eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","ninteen"};

  8.         char c[10][10]={"ten","twenty","thirty","fourty","fifty","sixty","seventy","eighty","ninty"};

  9.         int num,temp;

  10.         clrscr();

  11.         printf("

  12. Enter number:");

  13.         scanf("%d",&num);

  14.         printf("        num : %d",num);

  15.         if(num<=9999)

  16.         {

  17.                 if(num>=1000)

  18.                 {

  19.                         temp=num/1000;

  20.                         num=num%1000;

  21.                         printf("%s Thousand",a[temp-1]);

  22.                 }

  23.  

  24.                 if(num>=100)

  25.                 {

  26.                         temp=num/100;

  27.                         num=num%100;

  28.                         printf("%s Hundred and",a[temp-1]);

  29.                 }

  30.  

  31.                 if(num>10 && num<20)

  32.                 {

  33.                         temp=num%10;

  34.                         printf("%s ",b[temp-1]);

  35.                 }

  36.  

  37.                 if(num>19 && num<=100)

  38.                 {

  39.                         temp=num/10;

  40.                         num=num%10;

  41.                         printf("%s ",c[temp-1]);

  42.                 }

  43.                 if(num==10)

  44.                 {

  45.                         printf("%s",c[0]);

  46.                 }

  47.                 if(num<10)

  48.                 {

  49.                         printf("%s",a[num-1]);

  50.                 }

  51.                 if(num==0)

  52.                 {

  53.                         printf("zero");

  54.                 }

  55.         }

  56.         else

  57.         printf("

  58. Enter small number");

  59.         getch();

  60. }


  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.  

  5. int main(){

  6.  

  7.     int number,i=0,j,digit;

  8.     char * word[1000];

  9.  

  10.     printf("Enter any integer: ");

  11.     scanf("%d",&number);

  12.  

  13.     while(number){

  14.  

  15.     digit = number %10;

  16.     number = number /10;

  17.  

  18.          switch(digit){

  19.              case 0: word[i++] = "zero"; break;

  20.              case 1: word[i++] = "one"; break;

  21.              case 2: word[i++] = "two"; break;

  22.              case 3: word[i++] = "three"; break;

  23.              case 4: word[i++] = "four"; break;

  24.              case 5: word[i++] = "five"; break;

  25.              case 6: word[i++] = "six"; break;

  26.              case 7: word[i++] = "seven"; break;

  27.              case 8: word[i++] = "eight"; break;

  28.              case 9: word[i++] = "nine"; break;

  29.  

  30.          }

  31.     }

  32.    

  33.     for(j=i-1;j>=0;j--){

  34.          printf("%s ",word[j]);

  35.     }

  36.  

  37.     return 0;

  38.  

  39. }

  40.  


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. using namespace std;

  3. int x,e,b;

  4. void p(int n,int k,int o,int y);

  5. void c(int k,int l)

  6. {

  7.     if(k==0);

  8.     else if(k==1)

  9.     {

  10.         if(l==0)

  11.             cout<<"Ten ";

  12.         else if(l==1)

  13.             cout<<"Eleven ";

  14.         else if(l==2)

  15.             cout<<"Twelve ";

  16.         else if(l==3)

  17.             cout<<"Thirteen ";

  18.         else if(l==4)

  19.             cout<<"Fourteen ";

  20.         else if(l==5)

  21.             cout<<"Fifteen ";

  22.         else if(l==6)

  23.             cout<<"Sixteen ";

  24.         else if(l==7)

  25.             cout<<"Seventeen ";

  26.         else if(l==8)

  27.             cout<<"Eighteen ";

  28.         else if(l==9)

  29.             cout<<"Nineteen ";

  30.     }

  31.     else if(k==2)

  32.         cout<<"Twenty ";

  33.     else if(k==3)

  34.         cout<<"Thirty ";

  35.     else if(k==4)

  36.         cout<<"Forty ";

  37.     else if(k==5)

  38.         cout<<"Fifty ";

  39.     else if(k==6)

  40.         cout<<"Sixty ";

  41.     else if(k==7)

  42.         cout<<"Seventy ";

  43.     else if(k==8)

  44.         cout<<"Eighty ";

  45.     else if(k==9)

  46.         cout<<"Ninety ";

  47. }

  48. void ta(int n,int r,int q,int o,int u,int g)

  49. {

  50.     if(g!=0)

  51.     {

  52.         if (n==0);

  53.         else if(n==1);

  54.         else if(n==2)

  55.             c(r,q);

  56.         else if(n==3)

  57.             cout<<"Hundred ";

  58.         else if(n==4)

  59.             cout<<"Thousand ";

  60.         else if(n==5)

  61.             c(o,u);

  62.         else if(n==6)

  63.             cout<<"Lac ";

  64.         else if(n==7)

  65.             cout<<"Million ";

  66.         else if(n==8)

  67.             cout<<"Crore ";

  68.     }

  69.     else if(g==0 && n==4 && o!=0)

  70.         cout<<"Thousand ";

  71. }

  72. void under(int n,int o)

  73. {

  74.     int i,z,k,l,m,a;

  75.     for(i=0; i<o; i++)

  76.     {

  77.         z=n%10;

  78.         n=n/10;

  79.         if(i==1)

  80.             k=z;

  81.         else if(i==0)

  82.             l=z;

  83.         else if(i==4)

  84.             m=z;

  85.         else if(i==3)

  86.             a=z;

  87.     }

  88.     p(z,o,m,k);

  89.     ta(o,k,l,m,a,z);

  90.     b=k;

  91.     e=l;

  92. }

  93. void r(int n)

  94. {

  95.     if(n==0);

  96.     else if(n==1)

  97.         cout<<"One ";

  98.     else if(n==2)

  99.         cout<<"Two ";

  100.     else if(n==3)

  101.         cout<<"Three ";

  102.     else if(n==4)

  103.         cout<<"Four ";

  104.     else if(n==5)

  105.         cout<<"Five ";

  106.     else if(n==6)

  107.         cout<<"Six ";

  108.     else if(n==7)

  109.         cout<<"Seven ";

  110.     else if(n==8)

  111.         cout<<"Eight ";

  112.     else if(n==9)

  113.         cout<<"Nine ";

  114. }

  115. void p(int n,int k,int o,int y)

  116. {

  117.     if(k!=2 && k!=5 && k!=1 && k!=4)

  118.         r(n);

  119.     else if(k!=2 && k!=5 && y!=1 && o!=1 && k!=1)

  120.         r(n);

  121. }

  122. int main()

  123. {

  124.     int p=0,z,n;

  125.     cin>>x;

  126.     int i=0;

  127.     n=x;

  128.     for(; x>0; i++)

  129.     {

  130.         x=x/10;

  131.         z=x%10;

  132.         p++;

  133.     }

  134.     if(n==0)

  135.     {

  136.         cout<<"Zero";

  137.         return 0;

  138.     }

  139.     else if(p==1)

  140.     {

  141.             r(n);

  142.     }

  143.     else if(p>1)

  144.     {

  145.         for(i=0; p!=0; i++,p--)

  146.         {

  147.             under(n,p);

  148.         }

  149.         if(b!=1)

  150.             r(e);

  151.     }

  152. }

  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