C++ Exercises: Input any number and print it in words
C++ For Loop: Exercise-60 with Solution
Write a program in C++ to input any number and print it in words.
Pictorial Presentation:

Sample Solution:-
C++ Code :
#include <iostream>
using namespace std;
int main()
{
int n, num = 0, i;
cout << "\n\n Print a number in words:\n";
cout << "-----------------------------\n";
cout << " Input any number: ";
cin >> n;
while (n != 0) {
num = (num * 10) + (n % 10);
n /= 10;
}
for (i = num; i > 0; i = i / 10) {
switch (i % 10) {
case 0:
cout << "Zero ";
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;
}
}
cout << endl;
}
Sample Output:
Print a number in words: ----------------------------- Input any number: 8309 Eight Three Zero Nine
Flowchart:

C++ Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a program in C++ to find the frequency of each digit in a given integer.
Next: Write a program in C++ to print all ASCII character with their values.
What is the difficulty level of this exercise?
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join