The program converts given number to individual digits and print words, the program only prints all the digits of a number in just equivalent words, but it is not a meaningful sentence.
Example input:
456
325
-653
Example Output:
Four Five Six
Three Two Five
please enter valid number
The invalid numbers are any special symbols or negative numbers.
#include <stdio.h>
int main()
{
int num,rem=0,sum=0;
printf("enter the number :");
scanf("%d",&num);
while(num!=0)
{
rem=num%10;
sum=sum*10+rem;
num=num/10;
}
while(sum!=0)
{
rem=sum%10;
switch(rem)
{
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;
default:
printf("please enter valid number ");
exit(0);
}
sum=sum/10;
}
return 0;
}
The following codes might help you to dig more.
Java Program to Convert Number to Words
Java Program to Find Frequency Count of a Word in Given Text
C Program to Find Number of Characters and Words in a String
Testcase 1:
enter the number :3656 Three Six Five Six
Testcase 2:
enter the number :+6587 Six Five Eight Seven
Testcase 3:
enter the number :-9875 please enter valid number
Testcase 4:
enter the number :6+5+4+8 Six
Test Case 4 encountered a symbol, so the program stops execution with partial result. It is not a number.