#include<stdio.h>
#include<conio.h>
#include<string.h>
char string[100];
void convert(int n)
{
int r[5],i=0;
while(n>0)
{
r[i]=n%10;
n/=10;
i++;
}
while(i>0)
{
i--;
switch(r[i])
{
case 1: strcat(string,"ONE ");break;
case 2: strcat(string,"TWO ");break;
case 3: strcat(string,"THREE ");break;
case 4: strcat(string,"FOUR ");break;
case 5: strcat(string,"FIVE ");break;
case 6: strcat(string,"SIX ");break;
case 7: strcat(string,"SEVEN ");break;
case 8: strcat(string,"EIGHT ");break;
case 9: strcat(string,"NINE ");break;
case 0: strcat(string,"ZERO ");
}
}
}
void main()
{
int num;
clrscr();
printf("\nEnter the number : ");
scanf("%d",&num);
convert(num);
printf("\nWord\t\t : %s",string);
getch();
}
Algorithm
convert(n)step1:intilize i<-1
step2:check whether n>0,then go to step3
else go to step6
step3:r[i]=n%10
step4:n=n/10
step5:i=i+1
step5.5:go to step2
step6:check whether i>0,then go to step7
else go to step39
step7:i=i-1
step8:check whether r[i]=1,then go to step 9
else go to step11
step9:call strcat(string ,"one")
step10:break
step11:check whether r[i]=2,then go to step 12
else go to step14
step12:call strcat(string ,"two")
step13:break
step14:check whether r[i]=3,then go to step 15
else go to step17
step15:call strcat(string ,"three")
step16:break
step17:check whether r[i]=4,then go to step 18
else go to step20
step18:call strcat(string ,"four")
step19:break
step20:check whether r[i]=5,then go to step 21
else go to step23
step21:call strcat(string ,"five")
step22:break
step23:check whether r[i]=6,then go to step 24
else go to step26
step24:call strcat(string ,"six")
step25:break
step26:check whether r[i]=7,then go to step 27
else go to step29
step27:call strcat(string ,"seven")
step28:break
step29:check whether r[i]=8,then go to step 30
else go to step32
step30:call strcat(string ,"eight")
step31:break
step32:check whether r[i]=9,then go to step 33
else go to step35
step33:call strcat(string ,"nine")
step34:break
step35:check whether r[i]=0,then go to step 36
else go to step38
step36:call strcat(string ,"zero")
step37break
step38:go to step 6
step39:stop
main()
step1:start
step2:num
step3:call convert(num)
step4:print string
step5:stop