C Program to Convert a Number into Words [Simple Method]

POSTED BY Mohd ShibliCATEGORY C-programming

In this tutorial we will tech you how to write a C program to convert a given integer into words for example 23 will get converted into «Twenty Three».So lets start, The code for the above problem is given below:

Explaining the above code:

Note: The above program can only convert numbers below 10000. In the above example we declared three arrays which will hold the strings that we are going to use in converting the integer into string.We make use of pointers because directly we cannot use strings as a datatype in an array.
After that we calculate the length of the integer using the while loop, for example 23 will be of length '2'.Then using the if-else conditions we decide that on what length the string will use to be for example: if user entered 1 then the length will be one so the first condition will get executed and the compiler will pick the element from array ones[] and the element will be ones[x+1] where x=1 then the element will be ones[2] which is 'one'.This is how the above code is going to be executed.
Tweet your queries and feedback to @PsychoCodes or leave a message on our Facebook page. Also, don't forget to subscribe our newsletter.If you like the article then please share it and help us grow.

Понравилась статья? Поделиться с друзьями:
Добавить комментарий