Thank you my friend for your kind replay
with regards

--- On Tue, 1/7/08, Vishnu Kumar <[EMAIL PROTECTED]> wrote:
From: Vishnu Kumar <[EMAIL PROTECTED]>
Subject: Re: [c-prog] need a sample programme
To: [email protected]
Date: Tuesday, 1 July, 2008, 7:15 PM










    
            Hi,



Here i have attached the program which accepts 999 to 1 and outputs as words.

what here i developed 

1. accepts the input

2. reverse the number

3.find the starting index( purpose is where to start that means if input is 56 
then we have start from 2, if input is 7 then we have start from 1.

4. iterate the number( get individual digits)

    get the text from the char array by the index( here we use digit as index).



#include <stdio.h>



int main()

{

   int temp_number, reverse_number= 0,digit,number, start_index= 0;

   char number_string[ 200] = { "" };

   char single_digit[ ][20] = { "","one","two" ,"three", "four","five" 
,"six","seven" ,"eight", "nine" };

   char tenth_digit[ ][20] = { "","","twenty" ,"thirty" ,"fourty" ,"fifty", 
"sixty"," seventy", "eighty", "ninety" };

   char ten_plus_digit[ ][20] = { "ten","eleven" ,"twelve" ,"thirteen" 
,"fourteen" ,"fifteen" ,"sixteen" ,"seventeen" ,"eighteen" ,"nineteen" };

   clrscr();

   printf("Enter the number ");

   scanf("%d:", &number);

   temp_number = number;

   while(temp_number != 0)

   {

        digit = temp_number % 10;

        reverse_number = (reverse_number * 10) + digit;

        temp_number = temp_number/ 10;

   }



if(number >= 100 && number <=999)

   {

    start_index = 3;

   }

   else if(number >= 10 && number <=99)

   {

    start_index = 2;

   }

   else if(number < 10)

   {

       start_index = 3;

   }



while(reverse_ number != 0)

   {

            digit = reverse_number % 10;

               switch(start_ index)

               {

                   case 3:



if(digit != 0)

                           {

                                   strcat(number_ string,single_ digit[digit] );

                                   strcat(number_ string,"  hundred ");

                           }

                           start_index = 2;

                           break;

                   case 2:

                        start_index = 1;

                           if(digit != 0)

                           {

                                if(digit == 1)

                                {

                                    digit = (reverse_number/ 10 ) % 10;

                                       strcat(number_ string,ten_ plus_digit[ 
digit]);

                                       strcat(number_ string," ");

                                start_index = 0;

                                }

                                else

                                {

                                       strcat(number_ string,tenth_ 
digit[digit] );

                                       strcat(number_ string," ");

                                }

                        }

                           break;

                   case 1:

                           if(digit != 0)

                           {

                            strcat(number_ string,single_ digit[digit] );

                        }

                        start_index = 0;

               }

               reverse_number = reverse_number / 10;

     }



printf("\n %s",number_string) ;

     getch();

}



hope this meets your requirement.



~vishnu~



----- Original Message ----

From: osho ratha <[EMAIL PROTECTED] co.in>

To: [EMAIL PROTECTED] com

Sent: Tuesday, 1 July, 2008 12:59:53 PM

Subject: [c-prog] need a sample programme



hello friends,

i need a sample programme to convert numbers in words  in 'C'

for example:

225 

two hundred and twenty five.

thanking you,



Bollywood, fun, friendship, sports and more. You name it, we have it on 
http://in.promos. yahoo.com/ groups/bestofyah oo/



[Non-text portions of this message have been removed]



Bollywood, fun, friendship, sports and more. You name it, we have it on 
http://in.promos. yahoo.com/ groups/bestofyah oo/



[Non-text portions of this message have been removed]




      

    
    
        
         
        
        








        


        
        


      From Chandigarh to Chennai - find friends all over India. Go to 
http://in.promos.yahoo.com/groups/citygroups/

[Non-text portions of this message have been removed]

Reply via email to