Число в римска бройна система

Да се въведе число от 1 до 20 и да се изведе, записано в римска бройна система

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

14 коментара по Число в римска бройна система

  1. kr1stiqn1995 каза:
     
        int a;
        cout<<"Vavedete arabsko ch-lo:";
        cin>>a;
        switch(a) {
        case 1: cout<<"Otpechai I"<< endl;break;
        case 2: cout<<"Otpechai II"<< endl;break;
        case 3: cout<<"Otpechai III"<< endl;break;
        case 4: cout<<"Otpechai IV"<< endl;break;
        case 5: cout<<"Otpechai V"<< endl;break;
        case 6: cout<<"Otpechai VI"<< endl;break;
        case 7: cout<<"Otpechai VII"<< endl;break;
        case 8: cout<<"Otpechai VII"<< endl;break;
        case 9: cout<<"Otpechai IX"<< endl;break;
        case 10: cout<<"Otpechai X"<< endl;break;
        case 11: cout<<"Otpechai XI"<< endl;break;
        case 12: cout<<"Otpechai XII"<< endl;break;
        case 13: cout<<"Otpechai XIII"<< endl;break;
        case 14: cout<<"Otpechai XIV"<< endl;break;
        case 15: cout<<"Otpechai XV"<< endl;break;
        case 16: cout<<"Otpechai XVI"<< endl;break;
        case 17: cout<<"Otpechai XVII"<< endl;break;
        case 18: cout<<"Otpechai XVIII"<< endl;break;
        case 19: cout<<"Otpechai XIX"<< endl;break;
        case 20: cout<<"Otpechai XX"<< endl;break;
        default : cout<<"Nqma chislo!!";break;
    }
    
  2. Emili Cekova каза:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
      int a;
      cout<< " Vuvedi chislo  a , koeto da otgovarq na intervala ot 1 do 20 " <<endl ;
      cin>>a;
        switch (a) {
        case 1: cout<< " I" <<endl; break;
        case 2: cout<< " II " <<endl;break;
        case 3: cout<< " III " <<endl;break;
        case 4: cout<< " IV " <<endl;break;
        case 5: cout<< " V " <<endl;break;
        case 6: cout<< " VI " <<endl;break;
        case 7: cout<< " VII " <<endl;break;
        case 8: cout<< " VIII " <<endl;break;
        case 9: cout<< " IX " <<endl;break;
        case 10: cout<< " X " <<endl;break;
        case 11: cout<< " XI " <<endl;break;
        case 12: cout<< " XII " <<endl;break;
        case 13: cout<< " XIII " <<endl;break;
        case 14: cout<< " XIV " <<endl;break;
        case 15: cout<< " XV " <<endl;break;
        case 16: cout<< " XVI " <<endl;break;
        case 17: cout<< " XVII " <<endl;break;
        case 18: cout<< " XVIII " <<endl;break;
        case 19: cout<< " XIX " <<endl;break;
        case 20: cout<< " XX " <<endl;break;
        default: cout<< "Nevaliden izbor! " <<endl;break;
      }
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    
  3. Iceman каза:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    
     { int chislo;
       cout<<"Vavedete chislo ot 1 do 20"<<endl;
       cin>>chislo;
        switch (chislo){
       case 1:cout<<"I\n";break;
       case 2:cout<<"II\n";break;
       case 3:cout<<"III\n";break; 
       case 4:cout<<"IV\n";break;
       case 5:cout<<"V\n";break;
       case 6:cout<<"VI\n";break;
       case 7:cout<<"VII\n";break;
       case 8:cout<<"VIII\n";break;
       case 9:cout<<"IX\n";break;
       case 10:cout<<"X\n";break;
       case 11:cout<<"XI\n";break;
       case 12:cout<<"XII\n";break;
       case 13:cout<<"XIII\n";break;
       case 14:cout<<"XIV\n";break;
       case 15:cout<<"XV\n";break;
       case 16:cout<<"XVI\n";break;
       case 17:cout<<"XVII\n";break;
       case 18:cout<<"XVIII\n";break;
       case 19:cout<<"XIX\n";break;
       case 20:cout<<"XX\n";break;
       default:cout<<" Nqma takova chislo v tozi interval\n";
    }
       system("PAUSE");
        return EXIT_SUCCESS;
    }
    
     
  4. SvetoslavaPamela каза:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        int chislo;
        cout<<"Vuvedete chislo (ot 1 do 20): ";
        cin>>chislo;
        switch (chislo) 
        {
            case 1: cout<<" Chisloto e I ";break;
            case 2: cout<<" Chisloto e II ";break;
            case 3: cout<<" Chisloto e III ";break;
            case 4: cout<<" Chisloto e IV ";break;
            case 5: cout<<" Chisloto e V ";break;
            case 6: cout<<" Chisloto e VI ";break;
            case 7: cout<<" Chisloto e VII ";break;
            case 8: cout<<" Chisloto e VIII ";break;
            case 9: cout<<" Chisloto e IX ";break;
            case 10: cout<<" Chisloto e X ";break;
            case 11: cout<<" Chisloto e XI ";break;
            case 12: cout<<" Chisloto e XII ";break;
            case 13: cout<<" Chisloto e XIII ";break;
            case 14: cout<<" Chisloto e XIV ";break;
            case 15: cout<<" Chisloto e XV ";break;
            case 16: cout<<" Chisloto e XVI ";break;
            case 17: cout<<" Chisloto e XVII ";break;
            case 18: cout<<" Chisloto e XVIII ";break;
            case 19: cout<<" Chisloto e XIX ";break;
            case 20: cout<<" Chisloto e XX ";break;
       default:cout<<" Nevalidno chislo!\n";
        }
            
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    
  5. marant каза:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        int a;
        cout<<"vuvedi 4islotoot 1 do 20 ";
        cin>>a;
        if ((a>=1)&&(a<=20)) {
        if (a<11)
         switch (a){
                case 1:cout<<"I"<<endl;break;
                case 2:cout<<"II"<<endl;break;
                case 3:cout<<"III"<<endl;break;
                case 4:cout<<"IV"<<endl;break;
                case 5:cout<<"V"<<endl;break;
                case 6:cout<<"VI"<<endl;break;
                case 7:cout<<"VII"<<endl;break;
                case 8:cout<<"VIII"<<endl;break;
                case 9:cout<<"IX"<<endl;break;
                case 10:cout<<"X"<<endl;break;
                }
        if ((a>10)&&(a<21))
         cout<<"X";
         switch (a){
                case 11:cout<<"I"<<endl;break;
                case 12:cout<<"II"<<endl;break;
                case 13:cout<<"III"<<endl;break;
                case 14:cout<<"IV"<<endl;break;
                case 15:cout<<"V"<<endl;break;
                case 16:cout<<"VI"<<endl;break;
                case 17:cout<<"VII"<<endl;break;
                case 18:cout<<"VIII"<<endl;break;
                case 19:cout<<"IX"<<endl;break;
                case 20:cout<<"X"<<endl;break;
                } 
    }
    else cout<<"Ne e v intervala ili ne e 4islo"<<endl;
        system("PAUSE");
        return EXIT_SUCCESS;
    
    }
    
    • Данаил каза:

      Вярно! Но забележи – имаш два почти еднакви блока код. Следователно кода на програмата може още да се оптимизира. Например ако числото е над 10 и след отпечатване на Х извадиш 10 от него, ще може да ползваш първия switch и на двете места.

      • marant каза:
        #include <cstdlib>
        #include <iostream>
         
        using namespace std;
         
        int main(int argc, char *argv[])
        {
            int a;
            cout<<"vuvedi 4islotoot 1 do 20 ";
            cin>>a;
            if ((a>=1)&&(a<=20)) {
            if (a<10)
             switch (a){
                    case 1:cout<<"I"<<endl;break;
                    case 2:cout<<"II"<<endl;break;
                    case 3:cout<<"III"<<endl;break;
                    case 4:cout<<"IV"<<endl;break;
                    case 5:cout<<"V"<<endl;break;
                    case 6:cout<<"VI"<<endl;break;
                    case 7:cout<<"VII"<<endl;break;
                    case 8:cout<<"VIII"<<endl;break;
                    case 9:cout<<"IX"<<endl;break;
                    }
            if ((a>=10)&&(a<21))
             cout<<"X";
             switch (a){
                    case 10:cout<<""<<endl;break;
                    case 11:cout<<"I"<<endl;break;
                    case 12:cout<<"II"<<endl;break;
                    case 13:cout<<"III"<<endl;break;
                    case 14:cout<<"IV"<<endl;break;
                    case 15:cout<<"V"<<endl;break;
                    case 16:cout<<"VI"<<endl;break;
                    case 17:cout<<"VII"<<endl;break;
                    case 18:cout<<"VIII"<<endl;break;
                    case 19:cout<<"IX"<<endl;break;
                    case 20:cout<<"X"<<endl;break;
                    }
        }
        else cout<<"Ne e v intervala ili ne e 4islo"<<endl;
            system("PAUSE");
            return EXIT_SUCCESS;
         
        }
        
        • marant каза:
          #include <cstdlib>
          #include <iostream>
           
          using namespace std;
           
          int main(int argc, char *argv[])
          {
              int a;
              cout<<"vuvedi 4islotoot 1 do 20: ";
              cin>>a;
              if (a>10) {
                 cout<<"X";
                  a=a-10;
                        }
               switch (a){
                      case 1:cout<<"I"<<endl;break;
                      case 2:cout<<"II"<<endl;break;
                      case 3:cout<<"III"<<endl;break;
                      case 4:cout<<"IV"<<endl;break;
                      case 5:cout<<"V"<<endl;break;
                      case 6:cout<<"VI"<<endl;break;
                      case 7:cout<<"VII"<<endl;break;
                      case 8:cout<<"VIII"<<endl;break;
                      case 9:cout<<"IX"<<endl;break;
                      case 10:cout<<"X"<<endl;break;
                      }
          
          
              system("PAUSE");
              return EXIT_SUCCESS;
           
          }
           
  6. Gadget каза:
     
    int a;
        cout<<"Vavedi chislo (1-20):"<<endl;
        cin>>a;
    
    if((a>10)&&(a<=20))
        cout<<"X";
        if(((a>0)&&(a<=10))||((a>10)&&(a<=20))) 
        switch(a){
            case 1:
            case 11:cout<<"I"<<endl;break;
            case 2:
            case 12:cout<<"II"<<endl;break;
            case 3:
            case 13:cout<<"III"<<endl;break;
            case 4:
            case 14:cout<<"IV"<<endl;break;
            case 5:
            case 15:cout<<"V"<<endl;break;
            case 6:
            case 16:cout<<"VI"<<endl;break;
            case 7:
            case 17:cout<<"VII"<<endl;break;
            case 8:
            case 18:cout<<"VIII"<<endl;break;
            case 9:
            case 19:cout<<"IX"<<endl;break;
            case 10:
            case 20:cout<<"X"<<endl;break;
            default:cout<<"Nevalidno chislo!"<<endl;
        }
        else
        cout<<"Nevalidno chislo!"<<endl;
    
  7. Gadget каза:
     
    int
        a1,a;
        cout<<"Vavedi chislo (1-20):"<<endl;
        cin>>a1;    
        if(((a1>10)&&(a1<=20))||((a1>0)&&(a1<=10))){
        //Proverka dali chisloto e v intervala (11;20)                                            
        if((a1>10)&&(a1<=20))                                           
        cout<<"X";
        a=fabs(a1-10);
        //Proverka dali chisloto e v intervala (1;10)
        if((a1>0)&&(a1<=10))
        a=fabs(fabs(a1-10)-10);
        }
        switch(a){
            case 1:cout<<"I"<<endl;break;
            case 2:cout<<"II"<<endl;break;
            case 3:cout<<"III"<<endl;break;
            case 4:cout<<"IV"<<endl;break;
            case 5:cout<<"V"<<endl;break;
            case 6:cout<<"VI"<<endl;break;
            case 7:cout<<"VII"<<endl;break;
            case 8:cout<<"VIII"<<endl;break;
            case 9:cout<<"IX"<<endl;break;
            case 10:cout<<"X"<<endl;break;
            default:cout<<"Nevalidno chislo!"<<endl;
            }
     
  8. Gadget каза:
    int
        a1,a;
        cout<<"Vavedi chislo (1-20):"<<endl;
        cin>>a1;
        //Proverka dali chisloto e v intervala (11;20)                                            
        if((a1>10)&&(a1<=20))                                           
        cout<<"X";
        a=fabs(a1-10);
        //Proverka dali chisloto e v intervala (1;10)
        if((a1>0)&&(a1<=10))
        a=a1;
        switch(a){
            case 1:cout<<"I"<<endl;break;
            case 2:cout<<"II"<<endl;break;
            case 3:cout<<"III"<<endl;break;
            case 4:cout<<"IV"<<endl;break;
            case 5:cout<<"V"<<endl;break;
            case 6:cout<<"VI"<<endl;break;
            case 7:cout<<"VII"<<endl;break;
            case 8:cout<<"VIII"<<endl;break;
            case 9:cout<<"IX"<<endl;break;
            case 10:cout<<"X"<<endl;break;
            default:cout<<"Nevalidno chislo!"<<endl;
            }
            Още по–кратка форма на задачата.
    
  9. Gadget каза:
     
    int a,a1,a0,a10,a100;
        cout<<"Vavedi chislo (1-1000):"<<endl;
        cin>>a1;
        //Razdelqme chisloto na razlichni cifri
        a100=a1/100;
        a10=(a1/10)%10;
        a0=a1%10;
        
        if(a1>=100)
        switch(a100){
                     //Prevrushtame cifrata na stoticite v rimska broina sistema
                     case 1:cout<<"C";break;
                     case 2:cout<<"CC";break;
                     case 3:cout<<"CCC";break;
                     case 4:cout<<"CD";break;
                     case 5:cout<<"D";break;
                     case 6:cout<<"DC";break;
                     case 7:cout<<"DCC";break;
                     case 8:cout<<"DCCC";break;
                     case 9:cout<<"CM";break;
                     case 10:cout<<"M";break;
                     default:cout<<"Nevalidno chislo!"<<endl;
                     }       
        switch(a10){
                    //Prevrushtame cifrata na deseticite v rimska broina sistema
            case 0:cout<<"";break;
            case 1:cout<<"X";break;
            case 2:cout<<"XX";break;
            case 3:cout<<"XXX";break;
            case 4:cout<<"XL";break;
            case 5:cout<<"L";break;
            case 6:cout<<"LX";break;
            case 7:cout<<"LXX";break;
            case 8:cout<<"LXXX";break;
            case 9:cout<<"XC";break;
            default:cout<<"Nevalidno chislo!"<<endl;
            }
            
            switch(a0){
                       //Prevrushtame cifrata na edinicite v rimska broina sistema
                       case 1:cout<<"I"<<endl;break;
                       case 2:cout<<"II"<<endl;break;
                       case 3:cout<<"III"<<endl;break;
                       case 4:cout<<"IV"<<endl;break;
                       case 5:cout<<"V"<<endl;break;
                       case 6:cout<<"VI"<<endl;break;
                       case 7:cout<<"VII"<<endl;break;
                       case 8:cout<<"VIII"<<endl;break;
                       case 9:cout<<"IX"<<endl;break;
                       case 0:cout<<""<<endl;break;
                       default:cout<<"Nevalidno chislo!"<<endl;
                       }
     

    Reshenie do 1000

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