Thread: no. printing in words

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    46

    Red face no. printing in words

    if i have a no. 895 and i have to print it in words i.e. eight nine five. i can make use of sprintf and get it printed. suppose i need to take user input for the no.and then get it printed in words how shud i programme it???

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    It is a rather simple program.
    You read the input.
    You test which number you have and print it with words.
    For example:
    Code:
    switch(number) {
        case 1:
                   printf("one ");
                   break;
         case 2:
                    pritnf("two ");
                    break;
    ...
    }
    Do this for every digit and you are done

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Well "eight nine five" is considerably easier than say "eight hundred and ninety five".

    Just peel off each digit with /10 and %10 and you're almost done.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginners Contest #2 For those who wanted more!!
    By ILoveVectors in forum Contests Board
    Replies: 16
    Last Post: 08-12-2005, 12:03 AM
  2. Problem with malloc() and sorting words from text file
    By goron350 in forum C Programming
    Replies: 11
    Last Post: 11-30-2004, 10:01 AM
  3. Printing out 2 largest words
    By 0rion in forum C Programming
    Replies: 2
    Last Post: 06-02-2004, 12:51 AM
  4. New Theme
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 04-01-2004, 08:00 PM