Friday, 21 October 2011
C program for converting a 4 digit decimal number to words.
Do you like this story?
// Compiler Turbo-C
//This program will convert a four digit number to its equivalent worlds
// ex:- 3245=three thousand two hundred fourty five
// Program works only maximum up to 4 digit, But it can be extended.
//Developed by Amor J Kachari
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<string.h>
void main()
{
int num;
int po=3,s,di;
static char c[20];
do
{
clrscr();
printf("ENTER THE NUMBER OF FOUR DIGIT(only 4 digit is acceptable) : ");
scanf("%d",&num);
}
while(num>9999);
while(num>0)
{
di=pow(10,po);
s=num/di;
num=num%di;
if(po==1)
{
if(s==2)
strcat(c," twenty");
else if(s==3)
strcat(c," therty");
else if(s==4)
strcat(c," fourty");
else if(s==5)
strcat(c," fifty");
else if(s==1)
{
di=pow(10,po);
if(num%di==1)
strcat(c," eleven");
else if(num%di==2)
strcat(c," twelve");
else if(num%di==3)
strcat(c," therteen");
else if(num%di==3)
strcat(c," therten");
else if(num%di==4)
strcat(c," fourten");
else if(num%di==5)
strcat(c," fifthten");
else if(num%di==6)
strcat(c," sixten");
else if(num%di==7)
strcat(c," seventen");
else if(num%di==8)
strcat(c," eighten");
else if(num%di==9)
strcat(c," nineten");
goto fini;
}
goto n;
}
switch(s)
{
case 1:
strcat(c," one");
break;
case 2:
strcat(c," two");
break;
case 3:
strcat(c," three");
break;
case 4:
strcat(c," four");
break;
case 5:
strcat(c," five");
break;
case 6:
strcat(c," six");
break;
case 7:
strcat(c," seven");
break;
case 8:
strcat(c," eight");
break;
case 9:
strcat(c," nine");
break;
}
if(po==3&&s>0)
strcat(c," thousand");
if(po==2&&s>0)
strcat(c," hundred");
if(po==1)
{
if(s==4||s==6||s==7||s==8||s==9)
strcat(c,"ty");
}
n:
po--;
}
fini:
printf("%s",c);
getch();
getch();
}
Subscribe to:
Post Comments (Atom)
1 Responses to “C program for converting a 4 digit decimal number to words.”
21 October 2011 at 19:34
Itz gr8...i executed..........
Post a Comment