Wednesday, April 11, 2012

Converting input numerical string in C

The question is to write a program that takes an integer keyed in from the terminal and extracts and displays each digit of the integer in English. so, if a user types 932, the program should display 'nine three two'..



My algorithm is to reverse the number first so that 932 becomes 239. Now I extract the last digit using mod operator and print. Next I divide the number by 10, then I extract the last digit again and so on...



Is there any other algorithm (shorter and efficient) possible?



It is possible to extract the last digit of an integer. Is it possible to extract the first digit and so on?





No comments:

Post a Comment