# C Program: Converts number in digits to equivalent word

0
2258

This is a simple program  to convert number into words, for example if user enters “2451” then output will be “two thousand four hundred and fifty one”.

We start our code by including the header files “stdio.h”, ”conio.h” and “stdlib.h”. Now we initialize values 1-9 in double array o[][], 10-19 in array t1[][] and values like 20,30,40 till 90 in array t2[][]

Now we ask the user to input the number which is to be converted in words

### Convert number into words: For one digit number

Now the logic begins, if the number entered is less than 10 it will enter a for loop which will run till the value of “i” goes 0-10 and check if the number entered is equal to “i” if it is then array a[i] will be displayed on the output screen.

### Convert number into words: For two digit number

Now if the number entered is a two-digit number and is between 10-19 then it will enter the second condition, this condition is same as the first one it’s just that before it was checked that if the value of i is equal to value of number entered but now value of j will be checked instead of i as j is equals to i+10.

Now if, number is between 20- 99
then the output of the program is is displayed in two parts

1)The tens digit is found out by dividing the number and storing in an variable and then simply checking is inside the for loop and if its equal to the value of “i”  then t1[i] is displayed as the first part.

2)Now the number is deducted from the original number so the ones part remains and then it is also checked in a for loop and then displayed as the second part.

### Convert number into words: For three digit number

That is if the num is larger than 99 and smaller than 1000 then the same process if applied as in before, the number is divided into 3 parts the first is the hundred and it is displayed as the hundreds place digit is printed as it is in words using array “o[]” just adding the word “hundred” after it. After the hundreds place the left digits are checked in the are two digits or ones as in case if a number Is “201” then there is no tens digit.

### Convert number into words: For four digit number

4 digit number is also displayed in same manner as 3 digit manner first finding out the thousands place digit and displaying it as it is in words and just adding a thousand after it. After this the same logic is applied for hundred, tens and ones place as applied earlier.

My program only runs for a 4 digit number that is till “9999” and I am assuming that user will enter a value more than 0, but you can extend it for more digit number too by using same logic.

## Download Source Code – C Program: Converts number in digits to equivalent word

[sociallocker]Download Source Code – C Program: Converts number in digits to equivalent word