C Programming Code Examples C > For Loops and While Loops Code Examples program to print number in words program to print number in words Write a C program to input a number from user and print it into words using for loop. How to display number in words using loop in C programming. Logic to print number in words in C programming. Logic of convert number in words Input number from user. Store it in some variable say j. Extract last digit of given number by performing modulo division by 10. Store the result in a variable say digit = j % 10. Switch the value of digit found above. Since there are 10 possible values of digit i.e. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 hence, write 10 cases. Print corresponding word for each case. Remove last digit from j by dividing it by 10 i.e. j = j / 10. Repeat step 2 to 4 till number becomes 0. The above logic is correct however it print the words in reverse order. For example, suppose number is 1234, if you apply above logic the output printed is - "Four Three Two One" instead of "One Two Three Four". To overcome this, you must reverse the number. #include <stdio.h> int main() { int n, j = 0; /* Input number from user */ printf("Enter any number to print in words: "); scanf("%d", &n); /* Store reverse of n in j */ while(n != 0) { j = (j * 10) + (n % 10); n /= 10; } /* Extract last digit of number and print corresponding digit in words till j becomes 0 */ while(j != 0) { switch(j % 10) { case 0: printf("Zero "); break; case 1: printf("One "); break; case 2: printf("Two "); break; case 3: printf("Three "); break; case 4: printf("Four "); break; case 5: printf("Five "); break; case 6: printf("Six "); break; case 7: printf("Seven "); break; case 8: printf("Eight "); break; case 9: printf("Nine "); break; } j = j / 10; } return 0; }