A simple number to words converter in C programming language.
I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details. If you want to advertise on my website kindly contact me also in my email address also. Thank you.
I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details. If you want to advertise on my website kindly contact me also in my email address also. Thank you.
My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
My telephone number at home here in Bacolod City, Negros Occidental Philippines is +63 (034) 4335675.
Here in Bacolod I also accepting computer repair, networking and Arduino Project development at a very affordable price.
My personal website is http://www.jakerpomperada.com
Program Listing
number_words.c
#include<string.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
final_resort(long int num);
onebillion(long int x);
hundredmillion(long int x);
tenmillion(long int x);
onemillion(long int x);
hundredthou(long int x);
tenthou(long int x);
onethou(long int x);
hundred(long int x);
ten(long int x);
teen(int x);
one(int x);
char temp[200]=" ";
long int num;
void main(void)
{
printf("\t\t NUMBER TO WORDS CONVERTER IN C");
printf("\n\nGive a 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);
}
No comments:
Post a Comment