1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Program accepts number and displays in words....

Discussion in 'C' started by varun mca, Sep 1, 2010.

  1. varun mca

    varun mca New Member

    Sep 1, 2010
    Likes Received:
    Trophy Points:
    hello sir..
    I am not being able to make a program that accepts any number and displays it in words....
    for example: when user enter 3456 then output should be three thousand four hundred fifty six.... 12 then print twelve.....9 then print nine...and so on....
  2. techgeek.in

    techgeek.in New Member

    Dec 20, 2009
    Likes Received:
    Trophy Points:
    EOC (exploitation of computers)..i m a Terminator.
    Not an alien!! for sure
    Home Page:
    If I tell u the algorithm then will u be able to implement the program?? I hope u will...let me explain the algo..
    For solving such kind of problems u need to define several functions:-
    digit_count():- this function will count the number of digits of a number...
    one_digit(), two_digit(), three_digit(), four_digit() etc etc would be the functions which will give u the required string depending upon the number of digits..
    After counting the number of digits you need to pass the number to the actual function among the above defined functions..
    You also need to define the separate function for extrating the most significant number of a number... like if a number is 21..u need to extract 2 out of 21...if the number is 321..u need to split the number to 3 and 21...
    Now, in the functions one_digit(),two_digit().....u will have 9 cases. for example:- if the number is 1 digit u need to pass it to one_digit() and u will get different words for each number for 1 to 9...so u need 9 cases...
    Now,consider the number is of two digits (say 21)..then the number is passed to two_digit() and then inside operations is done to extract MSD i.e 2 and the 1 is again passed to one_digit...for each MSD u need to again define 9 cases from twenty for 2 to ninety for 9...additionally u need to define separate cases for special ones like eleven to nineteen....keep on continuing like this with ur algorithm..always remember that three_digit() will call two_digit() and two_digit() will call one_digit()...i mean the highest digits functions will utilize lower digit functions..... get back if you still have any issues..

Share This Page