Write a program which will convert digits/numbers into word in C
#include<stdio.h>
#include<conio.h>
#define MAX 10
int main(void)
{
int i,flag=0,number;
char arr0[10][6]={"","One","Two","Three","Four","Five","Six","Seven","Eight","Nine"};
char arr1[10][8]={"","Ten","Twenty","Thirty","Fourty","Fifty","Sixty","Seventy","Eighty","Ninety"};
char arr2[10][10]={"","Eleven","Tewelv","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"};
int k[10]={0,0,0,0,0,0,0,0,0,0};
printf("Enter the number: ");
scanf("%d",&number);
printf("\nIn word the number is:");
printf("\n\t\n");
if (number==0)
printf("Zero");
else
{
for(i=4;number>0;i--)
{
k[i]=number%10;
number/=10;
}
for(i=0;i<=4;i++)
{
if (k[i]>0||flag==1)
{
if (i==4)
if(k[3]==1)
printf("%s ",arr2[k[i]]);
else
printf("%s ",arr0[k[i]]);
else if (i==3)
if(k[3]==1 && k[4]>0)
{
}
else
printf("%s ",arr1[k[i]]);
else if (i==2 && k[i]>0)
printf("%s Hundred ",arr0[k[i]]);
else if (i==1)
{
if (k[0]==1)
{
}
else
printf("%s ",arr0[k[i]]);
printf("Thousand ");
}
else if (i==0)
{
if (k[0]==1 && k[1]>0)
printf("%s ",arr2[k[1]]);
else
printf("%s ",arr1[k[i]]);
flag=1;
}
}
}
}
printf("\n\n");
return 0;
}
#include<stdio.h>
#include<conio.h>
#define MAX 10
int main(void)
{
int i,flag=0,number;
char arr0[10][6]={"","One","Two","Three","Four","Five","Six","Seven","Eight","Nine"};
char arr1[10][8]={"","Ten","Twenty","Thirty","Fourty","Fifty","Sixty","Seventy","Eighty","Ninety"};
char arr2[10][10]={"","Eleven","Tewelv","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"};
int k[10]={0,0,0,0,0,0,0,0,0,0};
printf("Enter the number: ");
scanf("%d",&number);
printf("\nIn word the number is:");
printf("\n\t\n");
if (number==0)
printf("Zero");
else
{
for(i=4;number>0;i--)
{
k[i]=number%10;
number/=10;
}
for(i=0;i<=4;i++)
{
if (k[i]>0||flag==1)
{
if (i==4)
if(k[3]==1)
printf("%s ",arr2[k[i]]);
else
printf("%s ",arr0[k[i]]);
else if (i==3)
if(k[3]==1 && k[4]>0)
{
}
else
printf("%s ",arr1[k[i]]);
else if (i==2 && k[i]>0)
printf("%s Hundred ",arr0[k[i]]);
else if (i==1)
{
if (k[0]==1)
{
}
else
printf("%s ",arr0[k[i]]);
printf("Thousand ");
}
else if (i==0)
{
if (k[0]==1 && k[1]>0)
printf("%s ",arr2[k[1]]);
else
printf("%s ",arr1[k[i]]);
flag=1;
}
}
}
}
printf("\n\n");
return 0;
}