Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string conv(int x){
- if(x==0) return "zero";
- if(x==1) return "one";
- if(x==2) return "two";
- if(x==3) return "three";
- if(x==4) return "four";
- if(x==5) return "five";
- if(x==6) return "six";
- if(x==7) return "seven";
- if(x==8) return "eight";
- if(x==9) return "nine";
- }
- int main(){
- int n;
- cin>>n;
- int arr[10],i=0;
- int temp=n;
- while(temp){
- arr[i]=temp%10;
- i++;
- temp=temp/10;
- }
- //4
- // 968 arr={8,6,9}
- i--;
- int len=i;
- while(n!=0){
- int x=log10(n);
- int y=arr[i];// i=len
- i--;// i=len-1
- if(x==3){
- cout<<conv(y)<<" thousand ";
- }
- else if(x==2 and y!=0){
- if(i!=len-1) cout<<"and ";
- cout<<conv(y)<<" hundered ";
- }
- else if(x==1 and y!=0){
- if(i!=len-1) cout<<"and ";
- if(y==1) cout<<"ten ";
- else if(y==2) cout<<"twenty ";
- else if(y==3) cout<<"thirty ";
- else if(y==4) cout<<"fourty ";
- else if(y==5) cout<<"fifty ";
- else if(y==6) cout<<"sixty ";
- else if(y==7) cout<<"seventy ";
- else if(y==8) cout<<"eighty ";
- else if(y==9) cout<<"ninty ";
- }
- else{
- if(y!=0) cout<<conv(y)<<endl;
- }
- n=n/10;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment