Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3. using namespace std;
  4. const int n = 2;
  5. main()
  6. {
  7.       int a[n] = {},b[n] = {};
  8.       double S = 0, Sb = 0;
  9.       for(int i = 0; i<n; i++)
  10.       {
  11.       cin >> a[i] >> b[i];
  12.             if (a[i]>0)
  13.             {
  14.                        S=S + a[i];
  15.             }
  16.             if(b[i]<0)
  17.             {
  18.                        Sb=Sb+fabs(b[i]);
  19.             }
  20.            
  21.            
  22.  
  23.              
  24.       }
  25.      
  26.        if(S>Sb)
  27.        {
  28.                int c[n]={};
  29.                for(int i=0; i<n; i++)
  30.                {
  31.                        c[i]=a[i]+b[i];
  32.                        cout << c[i] << endl;
  33.                }
  34.        }
  35.                
  36.                
  37.        else
  38.        {
  39.              
  40.               for(int i=0; i<n; i++)
  41.                                  {
  42.                                          if(b[i]<0)
  43.                                          {
  44.                                          b[i]=0;
  45.                                          }
  46.                                  }
  47.      
  48.        }
  49.        
  50.      
  51. for(int i=0; i<n; i++)
  52.         {
  53.              cout << a[i] <<endl;
  54.         }
  55. for(int i=0; i<n; i++)
  56.          {
  57.               cout << b[i] <<endl;
  58.          }
  59. system("pause");
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement