Sanath12345

Untitled

Aug 20th, 2021
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. string conv(int x){
  2. if(x==0) return "zero";
  3. if(x==1) return "one";
  4. if(x==2) return "two";
  5. if(x==3) return "three";
  6. if(x==4) return "four";
  7. if(x==5) return "five";
  8. if(x==6) return "six";
  9. if(x==7) return "seven";
  10. if(x==8) return "eight";
  11. if(x==9) return "nine";
  12. }
  13. int main(){
  14. int n;
  15. cin>>n;
  16. int arr[10],i=0;
  17. int temp=n;
  18. while(temp){
  19. arr[i]=temp%10;
  20. i++;
  21. temp=temp/10;
  22. }
  23. //4
  24. // 968 arr={8,6,9}
  25. i--;
  26. int len=i;
  27. while(n!=0){
  28. int x=log10(n);
  29. int y=arr[i];// i=len
  30. i--;// i=len-1
  31.  
  32. if(x==3){
  33. cout<<conv(y)<<" thousand ";
  34. }
  35. else if(x==2 and y!=0){
  36. if(i!=len-1) cout<<"and ";
  37. cout<<conv(y)<<" hundered ";
  38. }
  39. else if(x==1 and y!=0){
  40. if(i!=len-1) cout<<"and ";
  41. if(y==1) cout<<"ten ";
  42. else if(y==2) cout<<"twenty ";
  43. else if(y==3) cout<<"thirty ";
  44. else if(y==4) cout<<"fourty ";
  45. else if(y==5) cout<<"fifty ";
  46. else if(y==6) cout<<"sixty ";
  47. else if(y==7) cout<<"seventy ";
  48. else if(y==8) cout<<"eighty ";
  49. else if(y==9) cout<<"ninty ";
  50. }
  51. else{
  52. if(y!=0) cout<<conv(y)<<endl;
  53. }
  54. n=n/10;
  55. }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment