Express a Number in English Words
Convert a non-negative integer to its representation in English words.
We'll cover the following...
Statement
Given a non-negative integer value, express it in English words.
Constraints
The maximum integer value to convert is billion.
The function should return -1
if the input number is negative or greater than billion.
Example
Sample input
1234
Expected output
"One Thousand Two Hundred Thirty Four"
Try it yourself
#include <iostream>using namespace std;string NumberToWords(int InputNumber) {// your code goes herereturn "";}
Solution
We can solve this problem by dividing the initial number into a specific set of digits and then converting those sets into English words. Initially, we split the number into sets of three. For example, if we split the amount into sets of three digits, we get ...