Събиране и изваждане на числа

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

   102
 +  24
 + 301
 = 427

По желание: Да се направи същото с дробни числа.

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

7 коментара по Събиране и изваждане на числа

  1. marant каза:
    #include <cstdlib>
    #include <iostream>
    #include <iomanip.h>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        int a,b;
        cout<<"Vuvedi 2 tricifreni 4isla: "<<endl;
        cin>>a>>b;
        cout<<setw(6)<<a<<endl;
        cout<<"+ "<<setw(4)<<b<<endl;
        cout<<"= "<<setw(4)<<(a+b)<<endl;
        
        system("PAUSE");
        return EXIT_SUCCESS;
    }
     
  2. Gadget каза:
    #include <iomanip.h>
    
    int x,y;
        cout<<"Vavedete dve tzeli chisla:"<<endl;
        cin>>x>>y;
        cout<<endl;
        //Subirane
        cout<<setw(5)<<x<<endl;
        cout<<"+"<<setw(4)<<y<<endl;
        cout<<"="<<setw(4)<<x+y<<endl;
        //Izvajdane
        cout<<endl;
        cout<<setw(5)<<x<<endl;
        cout<<"-"<<setw(4)<<y<<endl;
        cout<<"="<<setw(4)<<x-y<<endl;
        system("PAUSE");
        return 0;
     
  3. dreanor каза:
    #include <cstdlib>
    #include <iostream>
    #include <iomanip.h>
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        int a,b;
        char x;
        cout <<"Wuwedi dwete chisla: ";
        cin>>a>>b;
        cout <<"Wuwedi + za subirane ili - za izwajdane \n";
        cin>>x;
        if ((x=='+')||(x=='-'))
           {
            if (x=='+')
               {
                 cout<<"sumata e\n"<<setw(6)<<a<<endl;
                 cout<<"+\n"<<setw(6)<<b<<endl;
                 cout<<"<><><><><>"<<endl;
                 cout<<setw(6)<<(a+b)<<endl;
               }
            if (x=='-')
               {
                       
                 cout<<"razlikata e\n"<<setw(6)<<a<<endl;
                 cout<<"-\n"<<setw(6)<<b<<endl;
                 cout<<"<><><><><>"<<endl;
                 cout<<setw(6)<<(a-b)<<endl;
               }
           }
        else cout<<"newaliden simwol\n";
            
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    
  4. maleboldjia каза:
    #include <cstdlib>
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
    double a,b,c;
    cout<<"Vavedi purvoto chislo: "; cin>>a;
    cout<<"Vavedi vtoroto chislo: "; cin>>b;
    cout<<"Vavedi tretoto chislo: "; cin>>c;
    cout<<endl;
    cout<<a<<"+"<<b<<"+"<<c<<"="<<a+b+c<<endl;
    cout<<endl;
    cout<<setw(6)<<a<<endl;
       cout<<"+";
    cout<<setw(5)<<b<<endl;
       cout<<"+";
    cout<<setw(5)<<c<<endl;
       cout<<"---------"<<endl;
    cout<<setw(6)<<a+b+c<<endl;
    cout<<endl;
    cout<<a<<"-"<<b<<"-"<<c<<"="<<a-b-c<<endl;
    cout<<endl;
    cout<<setw(6)<<a<<endl;
       cout<<"-";
    cout<<setw(5)<<b<<endl;
       cout<<"-";
    cout<<setw(5)<<c<<endl;
       cout<<"---------"<<endl;
    cout<<setw(6)<<a-b-c<<endl;
    
    	system("pause");
    	return 0;
    }
    
  5. dreanor каза:
    #include <cstdlib>
    #include <iostream>
    #include <iomanip>
    #include <math.h>
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        double a,b,c;
        char x;
        bool fl1=1;
        cout <<"Wuwedi dwete chisla: ";
        cin>>a>>b;
        cout <<"Wuwedi + za subirane ili - za izwajdane \n";
        cin>>x;
    
       // izpulnqwa se glawnoto uslowe na zadachata 
        if (x=='+')
           {
             cout<<"sumata e\n"<<setw(6)<<a<<endl;
             cout<<"+\n"<<setw(6)<<b<<endl;
             cout<<"<><><><><>"<<endl;
             cout<<setw(6)<<(a+b)<<endl;
             c=a+b;
           }
        else if (x=='-')
           {
                   
             cout<<"razlikata e\n"<<setw(6)<<a<<endl;
             cout<<"-\n"<<setw(6)<<b<<endl;
             cout<<"<><><><><>"<<endl;
             cout<<setw(6)<<(a-b)<<endl;
             c=a-b;
           }   
        else { cout<<"newaliden simwol\n"; fl1=0; } //fl1 e prowerka za produljenie ( narochno sum naprawil wtorata chast da zawisi ot purwata )
        if (fl1==1)
           {
             cout <<"Iskash li da produljish operaciite s chisla (Y (da) ili N (ne) ) : "<<endl;
             cin>>x;
             if ((x=='Y')||(x=='y'))
                {
                  cout<<"wuwedi 0 za otkaz \n";
                  do                               //cikula do while garantira 1 izpulnenie na bloka kum nego
                    {
                     cout<<"wuwedi chislo: ";
                     cin>>a;                       //wuwejdaneto na otricatelno chislo se zachita za izwajdane
                     if (a<0)
                        {
                         cout<<setw(6)<<c<<endl;
                         a=fabs(a);                     
                         cout<<"-\n"<<setw(6)<<a<<endl;
                         cout<<"<><><><><>"<<endl;
                         cout<<setw(6)<<(c-a)<<endl;
                         c=(c-a);
                        }
                     else if (a>0)
                        {
                         cout<<setw(6)<<c<<endl;
                         cout<<"+\n"<<setw(6)<<a<<endl;
                         cout<<"<><><><><>"<<endl;
                         cout<<setw(6)<<(c+a)<<endl;
                         c=(c+a);
                        }
                    }while (a!=0);                  //stoinost nula na 'a' se priema za krai na izchisleniqta [ nikoi ne pribawq 0 :) ]
                }
             else if ((x=='N')||(x=='n')) cout<<"dobre!\n";
                  else cout<<"newaliden simwol\n";
           }        
        
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    

    Малко разширих условието на задачата :)

  6. Prizraka каза:

    #include
    #include
    #include

    using namespace std;

    int main(int argc, char *argv[])
    {
    int a,b;
    cout<>a>>b;
    cout<<setw(4)<<a<<endl;
    cout<<"+"<<endl;
    cout<<setw(4)<<b<<endl;
    cout<<"_____"<<endl;
    cout<<setw(4)<<(a+b)<<endl;
    system("PAUSE");
    return EXIT_SUCCESS;
    }

  7. LoL каза:
    #include <cstdlib>
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        int a,b,c;
        cout<<"vavedete purvoto chislo:"<<endl;
        cin>>a;
        cout<<"vavedete vtoroto chislo:"<<endl;
        cin>>b;
        cout<<setw(4)<<a<<endl;
        cout<<"+"<<endl;
        cout<<setw(4)<<b<<endl;
        cout<<"="<<endl;
        cout<<setw(4)<<a+b<<endl;
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    

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