Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>  
  3.  
  4. using namespace std;
  5.  
  6. int main (int argc, char *argv[])
  7. {
  8.  
  9. if(argc < 4) //First parameter is name of program
  10. {
  11.     cout << "\nIncorrect syntax. Usage: solve sum difference upperlimit" << endl;
  12.     return 1;
  13. }
  14.  
  15. int sum = stol(argv[1]); //since c++11
  16. int diff = stol(argv[2]);
  17. int max = stol(argv[3]);
  18.  
  19.     for(int x=0; x < max; ++x) //Use prefix increment
  20.     {
  21.         for(int y=0; y < max; ++y)
  22.         {
  23.             if( x + y == sum)
  24.             {
  25.                 cout << sum << "\n"
  26.                      << x << "\n"
  27.                      << y << "\n"
  28.                      << diff << endl;
  29.                
  30.                 if(abs(y - x) == diff)
  31.                 {
  32.                     cout << "\nSolutions are:" << "X=" << x << " " << "Y=" << y << endl;
  33.                     return 0;
  34.                 }
  35.             }
  36.         }
  37.     }
  38.    
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement