C Program to Convert Digits to its Equivalent Words

↑ Vote This Article

the program work till 4 digits of number

suppose the Input is: 1234

then the Output will be:  OneTwoThreeFour

Code:

//C Program to Convert Digits to its Equivalent Words
#include<stdio.h>
#include<conio.h>
void main()
{
int n,m,d,s=0,i,j,p,k;
clrscr();
printf(“Enter a 4 digit number\n\n”);
scanf(“%d”,&n);
m=n;
k=3;
if(n>9999)
{
printf(“\nNot a 4 digit number”);
}
else
for(i=1;i<=4;i++)
{
d=n%10;
p=1;
for(j=1;j<=k;j++)
{
p=p*10;
}
s=s+d*p;
n=n/10;
k–;
}
printf(“\nThe number %d in words is;”,m);
for(i=1;i<=4;i++)
{
d=s%10;
switch(d)
{
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;
}
s=s/10;
}
getch();
}

Also Read

C++ Program to Convert Digits to its Equivalent Words

Hope you liked my posts, give comments if you have any doubts… :)

———————————————————————————————————————————————————————————–

Tags: ,

Leave a comment