Friday, 3 January 2014

Figures To Words Program in C

This program accepts a three digit number from a user and the corresponding figure in words are displayed on the screen.

CODE=>

#include<stdio.h>
#include<conio.h>

void print(int a)
{
switch(a)
{
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 10:
printf("Ten ");
break;
case 11:
printf("Eleven ");
break;
case 12:
printf("Twelve ");
break;
case 13:
printf("Thirteen ");
break;
case 14:
printf("Fourteen ");
break;
case 15:
printf("Fifteen ");
break;
case 16:
printf("Sixteen ");
break;
case 17:
printf("Seventeen ");
break;
case 18:
printf("Eighteen ");
break;
case 19:
printf("Nineteen ");
break;
}
}

void print2(int b)
{
switch(b)
{
case 2:
printf("Twenty ");
break;
case 3:
printf("Thirty ");
break;
case 4:
printf("Fourty ");
break;
case 5:
printf("Fifty ");
break;
case 6:
printf("Sixty ");
break;
case 7:
printf("Seventy ");
break;
case 8:
printf("Eighty ");
break;
case 9:
printf("Ninety ");
break;
}
}

void main()
{
int num,r1,r2,r3,r4,num2,num3,num4;
clrscr();
printf("Enter a three digit number - ");
scanf("%d",&num);
r1=num%10;
num2=num/10;
r2=num2%10;
num3=num2/10;
r3=num3%10;
num4=num3/10;
r4=num4%10;

//printf("%d%d%d%d",r4,r3,r2,r1);
print(r4);
if(r4!=0)
printf("Thousand ");
print(r3);
if(r3!=0)
printf("Hundred ");
if(r2==1)
{
r2=num%100;
print(r2);
getch();
exit(0);
}
else
{
print2(r2);
}
print(r1);
getch();

}

OUTPUT=>


No comments:

Post a Comment