-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNumber to words
62 lines (49 loc) · 1.01 KB
/
Number to words
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
### Number to Words
#include <iostream>
#include <vector>
#include<bits/stdc++.h>
using namespace std;
int getbase(int num)
{
if(num/1000) return 1000;
if(num/100) return 100;
}
string basetoword(int num)
{
if(num/1000) return "thousand";
if(num/100) return "hundred";
}
string numtoword(int num)
{
string out="";
string ones[]={"","one","two","three","four","five","six","seven","eight","nine","ten"};
string teens[]={"","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
string tens[]={"","","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};
if(num<=10)
{
out= ones[num];
}
else if(num>10 && num<=19)
{
cout<<"came";
out =teens[num%10];
}
else if(num>19 && num<100)
{
out= tens[num/10] +" "+ ones[num%10];
}
else
{
int m=getbase(num);
out=numtoword(num/m) +" "+ basetoword(num) +" "+ numtoword(num%m);
}
//cout<<out;
return out;
}
int main()
{
int n=7774;
string s=numtoword(n);
cout<<s;
return 0;
}