CodesJava

Easy learning with example program codes

CPP program to print Numbers in form of Characters


The below program is to print the word representation of a number in CPP using loop.

Code:

#include <iostream.h>
using namespace std;
 
int main()
{  
int num,x;
int tot = 0;
 
cout << "Enter the number: ";    
cin >> num;    
 
while(num>0)    
{    
x = num%10;    
tot = tot*10 + x;    
num = num/10;    
}
 
while(tot>0)    
{    
x = tot%10;    
switch(x)    
{    
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 0:    
cout << "ZERO ";    
break;
default:    
cout << "INVALID INPUT ";    
break;   
}    
tot = tot/10;    
}    
return 0;
}

Output

Enter the number: 34786
THREE FOUR SEVEN EIGHT SIX
Posted in CPP   
Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki