July 15, 2024

# C or C++ Program to Convert Digit to Text

Convert Digit to Text or Convert Number into Text
Sometimes we need to convert a digit or number to text or word. Like number 420 – four hundred twenty. The following C++ program will convert a number to text.

C or C++ Code to Convert Digit to Text

```#include
#include
#include
#include

long   num,a;
long   num1;

int onetone(int num1)
{
switch(num1)
{
case 0 :                    ; break;
case 1 : cout<<" One"       ; break;
case 2 : cout<<" Two "       ; break;
case 3 : cout<<" Three"     ; break;
case 4 : cout<<" Four"      ; break;
case 5 : cout<<" Five"      ; break;
case 6 : cout<<" Six"       ; break;
case 7 : cout<<" Seven"     ; break;
case 8 : cout<<" Eight"     ; break;
case 9 : cout<<" Nine"      ; break;
case 10 : cout<<" Ten"      ; break;
case 11 : cout<<" Eleven"   ; break;
case 12 : cout<<" Twelve"   ; break;
case 13 : cout<<" Thirteen" ; break;
case 14 : cout<<" Fourteen" ; break;
case 15 : cout<<" Fifteen"  ; break;
case 16 : cout<<" Sixteen"  ; break;
case 17 : cout<<" Seventeen"; break;
case 18 : cout<<" Eighteen" ; break;
case 19 : cout<<" Nineteen" ; break;    }  }  int twentonn(int num1){    if((num>=0)&&(num1<=19))      onetone(num1);    else if((num>=20)&&(num1<=29))
{
cout<<" Twenty";         num1=num1%20;         onetone(num1);     }    else if((num>=30)&&(num1<=39))
{
cout<<" Thirty";         num1=num1%30;         onetone(num1);     }    else if((num>=40)&&(num1<=49))
{
cout<<" Forty";         num1=num1%40;         onetone(num1);     }    else if((num>=50)&&(num1<=59))
{
cout<<" Fifty";         num1=num1%50;         onetone(num1);     }    else if((num>=60)&&(num1<=69))
{
cout<<" Sixty";          num1=num1%60;          onetone(num1);     }    else if((num>=70)&&(num1<=79))
{
cout<<" Seventy";          num1=num1%70;          onetone(num1);     }    else if((num>=80)&&(num1<=89))
{
cout<<" Eighty";          num1=num1%80;          onetone(num1);      }    else if((num>=90)&&(num1<=99))
{
cout<<" Ninety";
num1=num1%90;
onetone(num1);
}
}

void main(){
char string[15];
clrscr();
cout<<"\" This program will convert a digit into text. \"\n\n";

cout<<"Please give a integer digit or number:";

gets(string);
a=atol(string);
num=labs(a);

cout<<endl<<"Your given digit or number is"<<endl;

if(a<0)
cout<<"-";      if(num>=10000000){
num1=num/10000000;
twentonn(num1);
cout<<" Crore";      num=num%10000000;      }      if(num>=100000){
num1=num/100000;
twentonn(num1);
cout<<" Lakh"; 	num=num%100000; 	}      if(num>=1000){
num1=num/1000;
twentonn(num1);
cout<<" Thousand"; 	num=num%1000; 	}      if(num>=100){
num1=num/100;
twentonn(num1);
cout<<" Hundred";
num=num%100;
}

if(num<100)
twentonn(num);

if(a==0)
cout<<"Zeroo";

getch();
}```

#### Rashedul Alam

I am a software engineer/architect, technology enthusiast, technology coach, blogger, travel photographer. I like to share my knowledge and technical stuff with others.

View all posts by Rashedul Alam →

## One thought on “C or C++ Program to Convert Digit to Text”

1. Akas says:

Really really good program. Its nice. Thanks