Число с думи

Да се напише програма, която позволява да се въведе положително едноцифрено число и го отпечатва с думи.

По желание: Програмата да може да прави същото и за двуцифрено число, а защо не и за трицифрено…

Публикувано в 11а, 11в с етикети . Постоянна връзка.

14 Responses to Число с думи

  1. Gadget каза:

    Reshenie za tricifreno chislo!

    Редакция Данаил: Оставих второто решение с коментарите, това изтрих.

  2. krisizdravi95 каза:
    int a;
    cout<<"Vuvedete chislo ";
    cin>>a;
    switch(a) {
        case 1: cout<<"edno"<<endl;break;
        case 2: cout<<"dve"<<endl;break;
        case 3: cout<<"tri"<<endl;break;
        case 4: cout<<"chetiri"<<endl;break;
        case 5: cout<<"pet"<<endl;break;
        case 6: cout<<"shest"<<endl;break;
        case 7: cout<<"sedem"<<endl;break;
        case 8: cout<<"osem"<<endl;break;
        case 9: cout<<"devet"<<endl;break;
        default: cout<<" Chisloto ne otgovarq na usloviqta"<<endl;
    }
    
  3. Gadget каза:
     
    int x,x1,x2,x3;
        cout<<"Vavedi tricifreno chislo:"<<endl;
        cin>>x;
        //Razdelqme tricifrenoto chislo na otdelni cifri!
        x3=x%10;
        x2=(x/10)%10;
        x1=x/100;
        //Naimenovame cifrata na stoticite!
        switch(x1){
    			case 1:cout<<"Sto";break;
    			case 2:cout<<"Dvesta";break;
    			case 3:cout<<"Trista";break;
    			case 4:cout<<"Chetiristotin";break;
    			case 5:cout<<"Petstotin";break;
    			case 6:cout<<"Sheststotin";break;
    			case 7:cout<<"Sedemstotin";break;
    			case 8:cout<<"Osemstotin";break;
    			case 9:cout<<"Devetstotin";break;
    			default:cout<<"Ne e tricifreno chislo!"<<endl;break;
        }
        //Naimenovame cifrata na deseticite!
        if(x2==1)
    			switch(x2){        
    				case 1:
    //Razglejdame sluchaqt pri koito cifrata na deseticite e 1!
    					switch(x3){
    						case 1:cout<<" i edinadeset !"<<endl;break;
    						case 2:cout<<" i dvanadeset !"<<endl;break;
    						case 3:cout<<" i trinadeset !"<<endl;break;
    						case 4:cout<<" i chetirinadeset !"<<endl;break;
    						case 5:cout<<" i petnadeset !"<<endl;break;
    						case 6:cout<<" i shestnadeset !"<<endl;break;
    						case 7:cout<<" i sedemnadeset !"<<endl;break;
    						case 8:cout<<" i osemnadeset !"<<endl;break;
    						case 9:cout<<" i devetnadeset !"<<endl;break;
    						case 0:cout<<" i deset !"<<endl;break;
    						default:cout<<"Ne e chislo !"<<endl;break;
    					};break;
    				case 2:cout<<" dvadeset";break;
    				case 3:cout<<" trideset";break;
    				case 4:cout<<" chetirideset";break;
    				case 5:cout<<" petdeset";break;
    				case 6:cout<<" sheiset";break;
    				case 7:cout<<" sedemdeset";break;
    				case 8:cout<<" osemdeset";break;
    				case 9:cout<<" devetdeset";break;
    				case 0:cout<<" ";break;
    				default:cout<<"Ne e chislo!"<<endl;break;
    			}
        else
    			switch(x2){
    				case 2:cout<<" dvadeset";break;
    				case 3:cout<<" trideset";break;
    				case 4:cout<<" chetirideset";break;
    				case 5:cout<<" petdeset";break;
    				case 6:cout<<" sheiset";break;
    				case 7:cout<<" sedemdeset";break;
    				case 8:cout<<" osemdeset";break;
    				case 9:cout<<" devetdeset";break;
    				case 0:cout<<" ";break;
    				default:cout<<"Ne e chislo!"<<endl;break; 
    			} 
    			//Naimenovame cifrata na edinicite!
        if(x2!=1)     
    			switch(x3){
    				case 1:cout<<" i edno !";break;
    				case 2:cout<<" i dve !";break;
    				case 3:cout<<" i tri !";break;
    				case 4:cout<<" i chetiri !";break;
    				case 5:cout<<" i pet !";break;
    				case 6:cout<<" i shest !";break;
    				case 7:cout<<" i sedem !";break;
    				case 8:cout<<" i osem !";break;
    				case 9:cout<<" i devet !";break;
    				case 0:cout<<" !";break;
    				default:cout<<"Ne e chislo !"<<endl;
    			}
     
  4. marant каза:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        int a;
        cout<<"vuvedi  4islo: ";
        cin>>a;
        if ((a>=1)&&(a<=99))
           if ((a>=1)&&(a<=11)){
           switch (a){
           case 1: cout<<"Edno"<<endl;break;
           case 2: cout<<"Dve"<<endl;break;
           case 4: cout<<"Tri"<<endl;break;
           case 5: cout<<"Chetiri"<<endl;break;
           case 6:cout<<"Pet"<<endl;break;
           case 7:cout<<"Sedem"<<endl;break;
           case 8: cout<<"Osem"<<endl;break;
           case 9: cout<<"Devet"<<endl;break;
           case 10: cout<<"deset"<<endl;break;
           case 11: cout<<"Edinadeset"<<endl;break;
           }}
              if ((a>=12)&&(a<=19))
                switch (a){
                  case 12:cout<<"Dvanadeset"<<endl;break;
                  case 13:cout<<"Trinadeset"<<endl;break;
                  case 14:cout<<"Chetirinadeset"<<endl;break;
                  case 15:cout<<"Petnadeset"<<endl;break;       
                  case 16:cout<<"Shestnadeset"<<endl;break;
                  case 17:cout<<"Sedemnadeset"<<endl;break;
                  case 18:cout<<"Osemnadeset"<<endl;break;
                  case 19:cout<<"devetnadeset"<<endl;break;
            }
              if ((a>=20)&&(a<=29))
                 switch (a){
                   case 20:cout<<"Dvanadeset"<<endl;break;
                   case 21:cout<<"Dvanadeset i edno"<<endl;break;
                   case 22:cout<<"Dvanadeset i dve"<<endl;break;
                   case 23:cout<<"Dvanadeset i tri"<<endl;break;
                   case 24:cout<<"Dvanadeset i Chetiri"<<endl;break;
                   case 25:cout<<"Dvanadeset i pet"<<endl;break;
                   case 26:cout<<"Dvanadeset i shest"<<endl;break;
                   case 27:cout<<"Dvanadeset i sedem"<<endl;break;
                   case 28:cout<<"Dvanadeset i osem"<<endl;break;
                   case 29:cout<<"Dvanadeset i devet"<<endl;break;
                   }
              if ((a>=30)&&(a<=39))
                 switch (a) {
                        case 30:cout<<"Trideset"<<endl;break;
                        case 31:cout<<"Trideset i edno"<<endl;break;
                        case 32:cout<<"Trideset i dve"<<endl;break;
                        case 33:cout<<"Trideset i tri"<<endl;break;
                        case 34:cout<<"Trideset i Chetiri"<<endl;break;
                        case 35:cout<<"Trideset i pet"<<endl;break;
                        case 36:cout<<"Trideset i shest"<<endl;break;
                        case 37:cout<<"Trideset i sedem"<<endl;break;
                        case 38:cout<<"Trideset i osem"<<endl;break;
                        case 39:cout<<"Trideset i devet"<<endl;break;
                        }
            system("PAUSE");
        return EXIT_SUCCESS;
    }
     

    Очаквайте ъпдейт

  5. dreanor каза:
    #include <iostream>
    #include <cstdlib>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    { 
    int x,a,b,c;
    cout << "Wuwedi chislo: ";
    cin>>x;
    if (x>999) cout << "Newalidno chislo";
       else
       {
            cout<<"chisloto e: ";
            if ((x>=100)&&(x<=999))
               {
                a=x/100;
                b=(x/10)%10;
                c=x%10;
                switch (a){
                    case 1:cout <<"Sto "; break;
                    case 2:cout <<"Dwesta "; break;
                    case 3:cout <<"Trista "; break;
                    case 4:cout <<"Chetiristotin "; break;
                    case 5:cout <<"Petstotin "; break;
                    case 6:cout <<"Sheststotin "; break;
                    case 7:cout <<"Sedemstotin "; break;
                    case 8:cout <<"Osemstotin "; break;
                    case 9:cout <<"Dewetstotin "; break;
                    }
                
               }
       if ((x<100)&&(x>=10))
       {
       b=x/10;
       c=x%10;
       }
        
       if ((b==1)&&((c<10)&&(c>=0)))
       {
       if ((x%10)!=0) cout <<"i ";
                 switch (c){
                    case 0:cout <<"deset "; break;
                    case 1:cout <<"edinadeset "; break;
                    case 2:cout <<"dwanadeset "; break;
                    case 3:cout <<"trinadeset "; break;
                    case 4:cout <<"chetirinadeset "; break;
                    case 5:cout <<"petnadeset "; break;
                    case 6:cout <<"shestnadeset "; break;
                    case 7:cout <<"sedemnadeset "; break;
                    case 8:cout <<"osemnadeset "; break;
                    case 9:cout <<"dewetnadeset "; break;
            }
       }
        else
            {
                 switch (b) {
                    case 2:cout <<"dwadeset ";break;
                    case 3:cout <<"trideset ";break;
                    case 4:cout <<"chetirideset ";break;
                    case 5:cout <<"petdeset ";break;
                    case 6:cout <<"shestdeset ";break;
                    case 7:cout <<"sedemdeset ";break;
                    case 8:cout <<"osemdeset ";break;
                    case 9:cout <<"dewetdeset ";break;
                 }
        if ((x%10)!=0) cout <<"i ";
        if (x<10) c=x;    
                 switch (c) {
                   case 1:cout <<"edno\n ";break;
                   case 2:cout <<"dwe\n ";break;
                   case 3:cout <<"tri\n ";break;
                   case 4:cout <<"chetiri\n ";break;
                   case 5:cout <<"pet\n ";break;
                   case 6:cout <<"shest\n ";break;
                   case 7:cout <<"sedem\n ";break;
                   case 8:cout <<"osem\n ";break;
                   case 9:cout <<"dewet\n ";break;
               }
             
                  
             {
    }
    }
    }
    system("PAUSE");
    return EXIT_SUCCESS;
    }
    
    • Данаил каза:

      Браво, Калояне! Спестил си излишните оператори switch, усетил си се да поставиш проверка кога да вмъква “ и „. Въобще – много добре! Само се чудя защо не намираш цифрите на едно място в началото? Липсват и коментари – задачата е доста дълга, постави на ключовите места по някой коментар…

  6. marant каза:

    Тук ги има числата от 1 до 199

    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        int a;
        cout<<"vuvedi 4isloto: ";
        cin>>a;
        if (a<=10)
           switch (a) {
                  case 1:cout<<"Edno"<<endl;break;
                  case 2:cout<<"Dve"<<endl;break;
                  case 3:cout<<"Tri"<<endl;break;
                  case 4:cout<<"Chetiri"<<endl;break;
                  case 5:cout<<"Pet"<<endl;break;
                  case 6:cout<<"Shest"<<endl;break;
                  case 7:cout<<"Sedem"<<endl;break;
                  case 8:cout<<"Osem"<<endl;break;
                  case 9:cout<<"Devet"<<endl;break;
                  case 10:cout<<"Deset"<<endl;break;
                  }
        if ((a>10)&&(a<20)){
           switch (a){
                  case 11:cout<<"Edi";break;
                  case 12:cout<<"Dva";break;
                  case 13:cout<<"Tri";break;
                  case 14:cout<<"Chetiri";break;
                  case 15:cout<<"Pet";break;
                  case 16:cout<<"Shes";break;
                  case 17:cout<<"Sedem";break;
                  case 18:cout<<"Osem";break;
                  case 19:cout<<"Devet";break;
                  }
                  cout<<"nadeset"<<endl; }
         if ((a>20)&&(a<30))
            cout<<"Dvadeset";
           switch (a){
                  case 20:cout<<""<<endl;break;
                  case 21:cout<<" i edno"<<endl;break;
                  case 22:cout<<" i dve"<<endl;break;
                  case 23:cout<<" i tri"<<endl;break;
                  case 24:cout<<" i chetiri"<<endl;break;
                  case 25:cout<<" i pet"<<endl;break;
                  case 26:cout<<" i shes"<<endl;break;
                  case 27:cout<<" i sedem"<<endl;break;
                  case 28:cout<<" i osem"<<endl;break;
                  case 29:cout<<" i devet"<<endl;break;
                  }
       if ((a>30)&&(a<40))
            cout<<"Trideset";
           switch (a){
                  case 30:cout<<""<<endl;break;
                  case 31:cout<<" i edno"<<endl;break;
                  case 32:cout<<" i dve"<<endl;break;
                  case 33:cout<<" i tri"<<endl;break;
                  case 34:cout<<" i chetiri"<<endl;break;
                  case 35:cout<<" i pet"<<endl;break;
                  case 36:cout<<" i shes"<<endl;break;
                  case 37:cout<<" i sedem"<<endl;break;
                  case 38:cout<<" i osem"<<endl;break;
                  case 39:cout<<" i devet"<<endl;break;
                  }
       if ((a>40)&&(a<50))
            cout<<"Chetiredeset";
           switch (a){
                  case 40:cout<<""<<endl;break;
                  case 41:cout<<" i edno"<<endl;break;
                  case 42:cout<<" i dve"<<endl;break;
                  case 43:cout<<" i tri"<<endl;break;
                  case 44:cout<<" i chetiri"<<endl;break;
                  case 45:cout<<" i pet"<<endl;break;
                  case 46:cout<<" i shes"<<endl;break;
                  case 47:cout<<" i sedem"<<endl;break;
                  case 48:cout<<" i osem"<<endl;break;
                  case 49:cout<<" i devet"<<endl;break;
                  }
             if ((a>50)&&(a<60))
            cout<<"Petdeset";
           switch (a){
                  case 50:cout<<""<<endl;break;
                  case 51:cout<<" i edno"<<endl;break;
                  case 52:cout<<" i dve"<<endl;break;
                  case 53:cout<<" i tri"<<endl;break;
                  case 54:cout<<" i chetiri"<<endl;break;
                  case 55:cout<<" i pet"<<endl;break;
                  case 56:cout<<" i shes"<<endl;break;
                  case 57:cout<<" i sedem"<<endl;break;
                  case 58:cout<<" i osem"<<endl;break;
                  case 59:cout<<" i devet"<<endl;break;
                  }
             if ((a>60)&&(a<70))
            cout<<"Sheiset";
           switch (a){
                  case 60:cout<<""<<endl;break;
                  case 61:cout<<" i edno"<<endl;break;
                  case 62:cout<<" i dve"<<endl;break;
                  case 63:cout<<" i tri"<<endl;break;
                  case 64:cout<<" i chetiri"<<endl;break;
                  case 65:cout<<" i pet"<<endl;break;
                  case 66:cout<<" i shes"<<endl;break;
                  case 67:cout<<" i sedem"<<endl;break;
                  case 68:cout<<" i osem"<<endl;break;
                  case 69:cout<<" i devet"<<endl;break;
                  }
             if ((a>70)&&(a<80))
            cout<<"Sedemdeset";
           switch (a){
                  case 70:cout<<""<<endl;break;
                  case 71:cout<<" i edno"<<endl;break;
                  case 72:cout<<" i dve"<<endl;break;
                  case 73:cout<<" i tri"<<endl;break;
                  case 74:cout<<" i chetiri"<<endl;break;
                  case 75:cout<<" i pet"<<endl;break;
                  case 76:cout<<" i shes"<<endl;break;
                  case 77:cout<<" i sedem"<<endl;break;
                  case 78:cout<<" i osem"<<endl;break;
                  case 79:cout<<" i devet"<<endl;break;
                  }
             if ((a>80)&&(a<90))
            cout<<"Osemdeset";
           switch (a){
                  case 80:cout<<""<<endl;break;
                  case 81:cout<<" i edno"<<endl;break;
                  case 82:cout<<" i dve"<<endl;break;
                  case 83:cout<<" i tri"<<endl;break;
                  case 84:cout<<" i chetiri"<<endl;break;
                  case 85:cout<<" i pet"<<endl;break;
                  case 86:cout<<" i shes"<<endl;break;
                  case 87:cout<<" i sedem"<<endl;break;
                  case 88:cout<<" i osem"<<endl;break;
                  case 89:cout<<" i devet"<<endl;break;
                  }
              if ((a>90)&&(a<100))
            cout<<"Devetdeset";
           switch (a){
                  case 90:cout<<""<<endl;break;
                  case 91:cout<<" i edno"<<endl;break;
                  case 92:cout<<" i dve"<<endl;break;
                  case 93:cout<<" i tri"<<endl;break;
                  case 94:cout<<" i chetiri"<<endl;break;
                  case 95:cout<<" i pet"<<endl;break;
                  case 96:cout<<" i shes"<<endl;break;
                  case 97:cout<<" i sedem"<<endl;break;
                  case 98:cout<<" i osem"<<endl;break;
                  case 99:cout<<" i devet"<<endl;break;
                  }
           if ((a>99)&&(a<200)) 
           cout<<"sto";
               if ((a>100)&&(a<=110))
           switch (a) {
                  case 101:cout<<" i edno"<<endl;break;
                  case 102:cout<<" i dve"<<endl;break;
                  case 103:cout<<" i tri"<<endl;break;
                  case 104:cout<<" i chetiri"<<endl;break;
                  case 105:cout<<" i pet"<<endl;break;
                  case 106:cout<<" i shest"<<endl;break;
                  case 107:cout<<" i sedem"<<endl;break;
                  case 108:cout<<" i osem"<<endl;break;
                  case 109:cout<<" i devet"<<endl;break;
                  case 110:cout<<" i deset"<<endl;break;
                  }
                  if ((a>110)&&(a<120)){
           switch (a){
                  case 111:cout<<" i edi";break;
                  case 112:cout<<" i dva";break;
                  case 113:cout<<" i tri";break;
                  case 114:cout<<" i chetiri";break;
                  case 115:cout<<" i pet";break;
                  case 116:cout<<" i shes";break;
                  case 117:cout<<" i sedem";break;
                  case 118:cout<<" i osem";break;
                  case 119:cout<<" i devet";break;
                  }
                  cout<<"nadeset"<<endl; }
         if ((a>120)&&(a<130))
            cout<<"dvadeset";
           switch (a){
                  case 120:cout<<""<<endl;break;
                  case 121:cout<<" i edno"<<endl;break;
                  case 122:cout<<" i dve"<<endl;break;
                  case 123:cout<<" i tri"<<endl;break;
                  case 124:cout<<" i chetiri"<<endl;break;
                  case 125:cout<<" i pet"<<endl;break;
                  case 126:cout<<" i shes"<<endl;break;
                  case 127:cout<<" i sedem"<<endl;break;
                  case 128:cout<<" i osem"<<endl;break;
                  case 129:cout<<" i devet"<<endl;break;
                  }
       if ((a>130)&&(a<140))
            cout<<"trideset";
           switch (a){
                  case 130:cout<<""<<endl;break;
                  case 131:cout<<" i edno"<<endl;break;
                  case 132:cout<<" i dve"<<endl;break;
                  case 133:cout<<" i tri"<<endl;break;
                  case 134:cout<<" i chetiri"<<endl;break;
                  case 135:cout<<" i pet"<<endl;break;
                  case 136:cout<<" i shes"<<endl;break;
                  case 137:cout<<" i sedem"<<endl;break;
                  case 138:cout<<" i osem"<<endl;break;
                  case 139:cout<<" i devet"<<endl;break;
                  }
          if ((a>140)&&(a<150))
            cout<<"Chetiredeset";
           switch (a){
                  case 140:cout<<""<<endl;break;
                  case 141:cout<<" i edno"<<endl;break;
                  case 142:cout<<" i dve"<<endl;break;
                  case 143:cout<<" i tri"<<endl;break;
                  case 144:cout<<" i chetiri"<<endl;break;
                  case 145:cout<<" i pet"<<endl;break;
                  case 146:cout<<" i shes"<<endl;break;
                  case 147:cout<<" i sedem"<<endl;break;
                  case 148:cout<<" i osem"<<endl;break;
                  case 149:cout<<" i devet"<<endl;break;
                  }
             if ((a>150)&&(a<160))
            cout<<"petdeset";
           switch (a){
                  case 150:cout<<""<<endl;break;
                  case 151:cout<<" i edno"<<endl;break;
                  case 152:cout<<" i dve"<<endl;break;
                  case 153:cout<<" i tri"<<endl;break;
                  case 154:cout<<" i chetiri"<<endl;break;
                  case 155:cout<<" i pet"<<endl;break;
                  case 156:cout<<" i shes"<<endl;break;
                  case 157:cout<<" i sedem"<<endl;break;
                  case 158:cout<<" i osem"<<endl;break;
                  case 159:cout<<" i devet"<<endl;break;
                  }
             if ((a>160)&&(a<170))
            cout<<"sheiset";
           switch (a){
                  case 160:cout<<""<<endl;break;
                  case 161:cout<<" i edno"<<endl;break;
                  case 162:cout<<" i dve"<<endl;break;
                  case 163:cout<<" i tri"<<endl;break;
                  case 164:cout<<" i chetiri"<<endl;break;
                  case 165:cout<<" i pet"<<endl;break;
                  case 166:cout<<" i shes"<<endl;break;
                  case 167:cout<<" i sedem"<<endl;break;
                  case 168:cout<<" i osem"<<endl;break;
                  case 169:cout<<" i devet"<<endl;break;
                  }
             if ((a>170)&&(a<180))
            cout<<"sedemdeset";
           switch (a){
                  case 170:cout<<""<<endl;break;
                  case 171:cout<<" i edno"<<endl;break;
                  case 172:cout<<" i dve"<<endl;break;
                  case 173:cout<<" i tri"<<endl;break;
                  case 174:cout<<" i chetiri"<<endl;break;
                  case 175:cout<<" i pet"<<endl;break;
                  case 176:cout<<" i shes"<<endl;break;
                  case 177:cout<<" i sedem"<<endl;break;
                  case 178:cout<<" i osem"<<endl;break;
                  case 179:cout<<" i devet"<<endl;break;
                  }
             if ((a>180)&&(a<190))
            cout<<"osemdeset";
           switch (a){
                  case 180:cout<<""<<endl;break;
                  case 181:cout<<" i edno"<<endl;break;
                  case 182:cout<<" i dve"<<endl;break;
                  case 183:cout<<" i tri"<<endl;break;
                  case 184:cout<<" i chetiri"<<endl;break;
                  case 185:cout<<" i pet"<<endl;break;
                  case 186:cout<<" i shes"<<endl;break;
                  case 187:cout<<" i sedem"<<endl;break;
                  case 188:cout<<" i osem"<<endl;break;
                  case 189:cout<<" i devet"<<endl;break;
                  }
              if ((a>190)&&(a<200))
            cout<<"Devetdeset";
           switch (a){
                  case 190:cout<<""<<endl;break;
                  case 191:cout<<" i edno"<<endl;break;
                  case 192:cout<<" i dve"<<endl;break;
                  case 193:cout<<" i tri"<<endl;break;
                  case 194:cout<<" i chetiri"<<endl;break;
                  case 195:cout<<" i pet"<<endl;break;
                  case 196:cout<<" i shes"<<endl;break;
                  case 197:cout<<" i sedem"<<endl;break;
                  case 198:cout<<" i osem"<<endl;break;
                  case 199:cout<<" i devet"<<endl;break;
                  }
                  
        system("PAUSE");
        return EXIT_SUCCESS;
    
    }
    
    • Данаил каза:

      Мартине. и двете задачи са верни, браво! Помислил си и за различните специфични случаи, които могат да създадат проблеми. Дали обаче не може още да се оптимизира кода? И тази, и другата ти задача с римските числа имат едно общо нещо – и в двете има повтарящи се почти еднакви блокове от код, които се различават само по константите след case. Понеже след case трябва да има константи, това не можем да променим, помисли, не може ли със съответни if-ове преди switch оператора в различните случаи така да преобразуваш числото, което подаваш в switch, че да ползваш само един switch за всички подобни случаи. Помисли кое е общото между всички повтарящи се блокове код и ще се сетиш какво да направиш с числото.

      Радвам се, че си намерил време вкъщи да поработиш по задачите…

  7. krisizdravi95 каза:
    int main(int argc, char **argv)
    { int a,a1,a2,a3;
    
    cout<<"Vuvedete polojitelno chislo: ";
    cin>>a;
    
    if((a<0)||(a>999)) {
    cout<<"Nevalidno chislo! \n";
    return 0;
    }
    
    
    if(a==0){
    cout<<" nula \n";
    return 0;
    }
    
    
    a1=a/100;
    a2=(a/10)%10;
    a3=a%10;
    
    
     if(a1>0) 
       switch(a1) {
    	case 1: cout<<"sto ";break;
    	case 2: cout<<"dvesta ";break;
    	case 3: cout<<"trista ";break;
    	case 4: cout<<"chetiristotin ";break;
    	case 5: cout<<"petstotin ";break;
    	case 6: cout<<"shestotin ";break;
    	case 7: cout<<"sedemstotin ";break;
    	case 8: cout<<"osemstotin ";break;
    	case 9: cout<<"devetstotin ";break;
    }
    
    if((a2==0)&&(a3==0))
    cout<<"\n";
    
    		 if(a2>1)
    switch(a2) {
    	case 2: cout<<" dvadeset";break;
    	case 3: cout<<" trideset";break;
    	case 4: cout<<" chetirideset";break;
    	case 5: cout<<" petdeset";break;
    	case 6: cout<<" sheiset";break;
    	case 7: cout<<" sedemdeset";break;
    	case 8: cout<<" osemdeset";break;
    	case 9: cout<<" devedeset";break;
    }
    
    
    if((a1>0)&&(a2==1))
    cout<<" i ";
    
                 if(a2==1)
    switch(a3) {
    	case 0: cout<<" deset\n";break;
    	case 1: cout<<" edinadeset\n";break;
    	case 2: cout<<" dvanadeset\n";break;
    	case 3: cout<<" trinadeset\n";break;
    	case 4: cout<<" chetirinadeset\n";break;
    	case 5: cout<<" petnadeset\n";break;
    	case 6: cout<<" shestnadeset\n";break;
    	case 7: cout<<" sedemnadeset\n";break;
    	case 8: cout<<" osemnadeset\n";break;
    	case 9: cout<<" devetnadeset\n";break;
    }
    
    
    if((a2>1)&&(a3!=0))
    cout<<" i ";
    
    
    if((a3>0)&&(a2!=1))
    switch(a3) {
    	case 1: cout<<" edno\n";break;
    	case 2: cout<<" dve\n";break;
    	case 3: cout<<" tri\n";break;
    	case 4: cout<<" chetiri\n";break;
    	case 5: cout<<" pet\n";break;
    	case 6: cout<<" shest\n";break;
    	case 7: cout<<" sedem\n";break;
    	case 8: cout<<" osem\n";break;
    	case 9: cout<<" devet\n";break;
    }
    
    
    
    
    	
    	return 0;
    }
    
    • Данаил каза:

      Кристина, какво си направила!!!!! Погледни само, не мога да повярвам! Олеле…

      Шегичка :) Много добре направено – и разглеждането на всички варианти, и спирането на програмата при нула и големи числа, и форматирането дори. Браво, решението е направо бижу…

      • krisizdravi95 каза:

        Да знаете, че в момента ме карат в болницата, защото получих инфаркт!
        Относно задачата – публикувах я с един пропуск, но след много старание и следователно отчаяние. Исках да отпечатва грешка, когато някой (в нашия случай баща ми) реши да въведе букви. Опитах с ifdigit, но то не включва нулата.

        • Данаил каза:

          Ха ха ха :)))

          Кристина!!! Бива ли за една задача инфаркт да получаваш! Засрами се…

          isdigit ти проверява дали даден символ е число, така че нямаше да ти свърши работа или щеше да направи програмата прекалено сложна. В този специално случай по-ефективния вариант е леко смъмряне на бащата…

Вашият коментар