Advertisement
khisby

angka dan kata angka

Nov 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. void satuan (int a)
  7. {
  8.     if (a==1) {
  9.         cout<<" Satu ";
  10.     }else if (a==2) {
  11.         cout<<" Dua ";
  12.     }else if (a==3) {
  13.         cout<<" Tiga ";
  14.     }else if (a==4) {
  15.         cout<<" Empat ";
  16.     }else if (a==5) {
  17.         cout<<" Lima ";
  18.     }else if (a==6) {
  19.         cout<<" Enam ";
  20.     }else if (a==7) {
  21.         cout<<" Tujuh ";
  22.     }else if (a==8) {
  23.         cout<<" Delapan ";
  24.     }else if (a==9) {
  25.         cout<<" Sembilan ";
  26.     }else if (a==10) {
  27.         cout<<" Sepuluh ";
  28.     }else if (a==11) {
  29.         cout<<" Sebelas ";
  30.     }
  31. }
  32. void terbilang (int b){
  33.     if (b<=11) {
  34.         satuan(b);
  35.     }else if((b>11) && (b<=19)){
  36.         terbilang(b%10);
  37.         cout<<"Belas ";
  38.     }else if ((b>=20)&&(b<=99)) {
  39.         terbilang(b/10);
  40.         cout<<"Puluh";
  41.         terbilang(b%10);
  42.     }else if ((b>=100)&&(b<=199)) {
  43.         cout<<"Seratus";
  44.         terbilang(b%100);
  45.     }else if ((b>=200)&&(b<=999)) {
  46.         terbilang(b/100);
  47.         cout<<"Ratus";
  48.         terbilang(b%100);
  49.     }else if ((b>=1000)&&(b<=1999)) {
  50.         cout<<"Seribu";
  51.         terbilang(b%1000);
  52.     }else if ((b>=2000)&&(b<=9999)) {
  53.         terbilang(b/1000);
  54.         cout<<"Ribu";
  55.         terbilang(b%1000);
  56.     }else if ((b>=10000)&&(b<=99999)) {
  57.         terbilang(b/1000);
  58.         cout<<"Ribu";
  59.         terbilang(b%1000);
  60.     }else if ((b>=100000)&&(b<=999999)) {
  61.         terbilang(b/1000);
  62.         cout<<"Ribu";
  63.         terbilang(b%1000);
  64.     }else if ((b==1000000)) {
  65.         terbilang(b/1000000);
  66.         cout<<"Juta";
  67.         terbilang(b%1000000);
  68.     }else if ((b>1000000)){
  69.         cout<<"ERROR\n";
  70.         cout<<"nilai yang Anda masukan melampaui database aplikasi";
  71.     }
  72. }
  73. int main()
  74. {
  75.     int nilai;
  76.     string angka;
  77.     cout<<"Masukkan Bilangan Anda: ";
  78.     cin>>nilai;
  79.         int i=1;
  80.         while(i<=nilai){
  81.             cout << i;
  82.             terbilang(i);
  83.             cout << endl;
  84.             i++;
  85.         }
  86.     cout<<"\n============================\n";
  87.     return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement