VB icon

Num to Word converssion

Email
Submitted on: 4/4/2016 4:28:46 PM
By: SAMIR 
Level: Intermediate
User Rating: By 1 Users
Compatibility: C
Views: 2017
author picture
 
     INTEGER NUMBER TO WORDS CONVERSION PROGRAM

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Num to Word converssion
// Description:INTEGER NUMBER TO WORDS CONVERSION PROGRAM
// By: SAMIR
//**************************************

#include<string.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
//Title: Number to words conversion
//Author: Samir Biswas
//Friendster:samirbiswas47@gmail.com
/* 1,000,000 equal to One million [10^6]
1000,000,000 equal to One billion [10^9] */
int final_resort(long int num);
int onebillion(long int x);
int hundredmillion(long int x);
int tenmillion(long int x);
int onemillion(long int x);
int hundredthou(long int x);
int tenthou(long int x);
int onethou(long int x);
int hundred(long int x);
int ten(long int x);
int teen(int x);
int one(int x);
char temp[200]=" ";
long int num;
void main(void)
{
printf("\n******************** INTEGER NUMBER TO WORDS CONVERSION PROGRAM ****************");
printf("\n\nInput Number: ");scanf("%ld",&num);
printf("\n");
if (num<1412999999&&num>=1)
{
final_resort(num);
printf("In Words: %s",temp);
}
else if(num>=1412999999)
{
printf("\nError: Input Value must be less than 1,412,999,999!");
}
else {
printf("Error: Cannot convert the inputed value!" );
}
getch();
}
//last resort
final_resort(long int num)
{
char str1[20];
int lengs;
sprintf(str1,"%ld",num);
lengs=strlen(str1);
switch (lengs)
{
case 1:
one(num);
break;
case 2:
ten(num);
break;
case 3:
hundred(num);
break;
case 4:
onethou(num);
break;
case 5:
tenthou(num);
break;
case 6:
hundredthou(num);
break;
case 7:
onemillion(num);
break;
case 8:
tenmillion(num);
break;
case 9:
hundredmillion(num);
break;
case 10:
onebillion(num);
break;
}
}
//one
one(int x)
{
switch (x)
{
case 1:
strcat(temp,"one ");
break;
case 2:
strcat(temp,"two ");
break;
case 3:
strcat(temp,"three ");
break;
case 4:
strcat(temp,"four ");
break;
case 5:
strcat(temp,"five ");
break;
case 6:
strcat(temp,"six ");
break;
case 7:
strcat(temp,"seven ");
break;
case 8:
strcat(temp,"eight ");
break;
case 9:
strcat(temp,"nine ");
break;
}
}
//teens
teen(int x)
{
switch (x)
{
case 10:
strcat(temp,"ten ");
break;
case 11:
strcat(temp,"eleven ");
break;
case 12:
strcat(temp,"twelve ");
break;
case 13:
strcat(temp,"thirteen ");
break;
case 14:
strcat(temp,"fourteen ");
break;
case 15:
strcat(temp,"fifteen ");
break;
case 16:
strcat(temp,"sixteen ");
break;
case 17:
strcat(temp,"seventeen ");
break;
case 18:
strcat(temp,"eighteen ");
break;
case 19:
strcat(temp,"nineteen ");
break;
}
}
//ten
ten(long int x)
{
long int q,m;
q=x/10;
m=x%10;
switch (q)
{
case 2:
strcat(temp,"twenty ");
one(m);
break;
case 3:
strcat(temp,"thirty ");
one(m);
break;
case 4:
strcat(temp,"fourty ");
one(m);
break;
case 5:
strcat(temp,"fifty ");
one(m);
break;
case 6:
strcat(temp,"sixty ");
one(m);
break;
case 7:
strcat(temp,"seventy ");
one(m);
break;
case 8:
strcat(temp,"eighty ");
one(m);
break;
case 9:
strcat(temp,"ninety ");
one(m);
break;
}
if (x>=10&&x<=19)
{
teen(x);
}
else if (x>=1&&x<=9)
{
one(x);
}
}
//hundred
hundred(long int x)
{
long int q2,p2,d2;
q2=x/100;
p2=q2*100;
d2=x-p2;
switch (q2)
{
case 1:
one(q2);
strcat(temp,"hundred ");
ten(d2);
break;
case 2:
one(q2);
strcat(temp,"hundred ");
ten(d2);
break;
case 3:
one(q2);
strcat(temp,"hundred ");
ten(d2);
break;
case 4:
one(q2);
strcat(temp,"hundred ");
ten(d2);
break;
case 5:
one(q2);
strcat(temp,"hundred ");
ten(d2);
break;
case 6:
one(q2);
strcat(temp,"hundred ");
ten(d2);
break;
case 7:
one(q2);
strcat(temp,"hundred ");
ten(d2);
break;
case 8:
one(q2);
strcat(temp,"hundred ");
ten(d2);
break;
case 9:
one(q2);
strcat(temp,"hundred ");
ten(d2);
break;
}
if (q2<=0)
{
ten(x);
}
}
//thousands
onethou(long int x)
{
long int q1,p1,d1;
q1=x/1000;
p1=q1*1000;
d1=x-p1;
one(q1);
strcat(temp,"thousand ");
hundred(d1);
}
//tenthousands
tenthou(long int x)
{
long int q1,m;
q1=x/1000;
m=x%1000;
ten(q1);
strcat(temp,"thousand ");
hundred(m);
}
//hundredthousand
hundredthou(long int x)
{
long int q1,q2;
long int m1,m2;
q1=x/100000;
m1=x%100000;
one(q1);
strcat(temp,"hundred ");
q2=m1/1000;
m2=m1%1000;
ten(q2);
strcat(temp,"thousand ");
hundred(m2);
}
//one million
onemillion(long int x)
{
long int q1,q2;
long int m1,m2;
q1=x/1000000;
m1=x%1000000;
one(q1);
strcat(temp,"million ");
q2=m1/1000;
m2=m1%1000;
hundred(q2);
if (q2!=0)
{
strcat(temp,"thousand ");
}
hundred(m2);
}
//ten million
tenmillion(long int x)
{
long int q1,q2;
long int m1,m2;
q1=x/1000000;
m1=x%1000000;
ten(q1);
strcat(temp,"million ");
q2=m1/1000;
m2=m1%1000;
hundred(q2);
if (q2!=0)
{
strcat(temp,"thousand ");
}
hundred(m2);
}
//hundred million
hundredmillion(long int x)
{
long int q1,q2;
long int m1,m2;
q1=x/1000000;
m1=x%1000000;
hundred(q1);
strcat(temp,"million ");
q2=m1/1000;
m2=m1%1000;
hundred(q2);
if (q2!=0)
{
strcat(temp,"thousand ");
}
hundred(m2);
}
//onebillion
onebillion(long int x)
{
long int q1,q2,q3;
long int m1,m2,m3;
q1=x/1000000000;
m1=x%1000000000;
one(q1);
strcat(temp,"billion ");
q2=m1/1000000;
m2=m1%1000000;
hundred(q2);
if (q2!=0)
{
strcat(temp,"million ");
}
q3=m2/1000;
m3=m2%1000;
hundred(q3);
if (q3!=0)
{
strcat(temp,"thousand ");
}
hundred(m3);
}


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.