C Programming: How to Display Output from Numbers to Words?
Hello guys! I'm new in C programming and i want to know how to display out in words if number is inputed, using switch or an if..else statement. I have a little program sample but in my case the number inputed not would be greater than 9000.
Example:
if inputed is 168
The output will be "One Hundred-Sixty Eight"
I have a program but it only prints 1-10 ..T_T
Here's the code:
Code:
#include<stdio.h>
void main()
{
int i=0;
unsigned long int digit;
char str[12],ch;
puts(“Enter the number (less than 10 digit)”);
scanf(“%lu”,&digit);
ultoa(digit,str,10); /*converts an unsigned long int to string*/
while(str[i]!=’\0′)
{
ch=str[i];
i++;
switch(ch)
{
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;
case ’0′:
printf(“ZERO “);
break;
}
}
}
That's the code i could only create but i need to know when big numbers is inputed and printing in words.Thanks!