## 6.04.2014

### Convert Any Digital Number Value In Words

Q. Write a C program that convert any digital number value in worlds as:

User entered value: 895484
then output in words as:
Eight Lakh Ninety Five Thousand Four Hundred Eighty Four

Ans.

/*c program that convert any digital number to words*/
#include<stdio.h>
#include<conio.h>
#include<math.h>

void checkNumber(int num);
void checkNumber1(int num);
void checkNumber2(int num);
void checkNumber3(int num);
void checkNumber4(int num);

void value1(int num);
void value2(int num);
void value3(int num1,int num2);

int main()
{

int num;

printf("Enter any Number : ");
scanf("%d",&num);
printf("Entered Number is : ");
if(num<=100)
checkNumber1(num);
else if(num>100 && num<1000)
checkNumber2(num);
else if(num>=1000 && num<=100000)
checkNumber3(num);
else if(num>100000 && num<=10000000)
checkNumber4(num);
else
checkNumber(num);
getch();
return 0;
}

void checkNumber(num)
{
printf("Kindly enter the number between 0 to 10000000");
}

void checkNumber1(num)
{
int x,y,z;
if(num>=0 && num<=10)
value1(num);
else if(num>10 && num<20)
{
x=num%10;
value2(x);
}
else if(num>=20 && num<=100)
{
y=num/10;
z=num%10;
value3(y,z);
}
}

void checkNumber2(int num)
{
int x,y,z;
y=num/100;
value1(y);
printf(" Hundred ");
x=num%100;
checkNumber1(x);
}

void checkNumber3(int num)
{
int x,y,z;
if(num==1000)
{
printf(" Thousand ");
exit(0);
}
else if(num==100000)
{
printf("Lakh");
exit(0);
}
else
{
x=num/1000;
checkNumber1(x);
printf(" Thousand ");
z=num%1000;
if(z<=99)
checkNumber1(z);
else
checkNumber2(z);
}
}

void checkNumber4(int num)
{
int x,y;
if(num==10000000)
{
printf("One Crore");
exit(0);
}
x=num/100000;
checkNumber1(x);
printf(" Lakhs ");
y=num%100000;
if(y==0)
exit(0);
else if(y<=99)
checkNumber1(y);
else if(y>99 && y<=999)
checkNumber2(y);
else
checkNumber3(y);
}

void value1(int num)
{
switch(num)
{
case 0: printf("Zero"); break;
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;
default: printf("");
}
}

void value2(int num)
{
switch(num)
{
case 1: printf("Eleven"); break;
case 2: printf("Twelve"); break;
case 3: printf("Thirteen"); break;
case 4: printf("Fourteen"); break;
case 5: printf("Fifteen"); break;
case 6: printf("Sixteen"); break;
case 7: printf("Seventeen"); break;
case 8: printf("Eighteen"); break;
case 9: printf("Nineteen"); break;
default: printf("");
}
}
void value3(int num1,int num2)
{
switch(num1)
{
case 2: printf("Twenty "); break;
case 3: printf("Thirty "); break;
case 4: printf("Forty "); 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;
case 10: printf("Hundred"); break;
default: printf("");
}
value1(num2);

}

/*************************************************************
The output of above program would be:
**************************************************************/

 Figure-1: Screen shot for convert number to words C program

 Figure-2: Screen shot for convert number to words C program

Related program:

#### 1 comment:

1. Nice program..never think to do this kind of project in 'C'