Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main (int argc, char *argv[])
- {
- if(argc < 4) //First parameter is name of program
- {
- cout << "\nIncorrect syntax. Usage: solve sum difference upperlimit" << endl;
- return 1;
- }
- int sum = stol(argv[1]); //since c++11
- int diff = stol(argv[2]);
- int max = stol(argv[3]);
- for(int x=0; x < max; ++x) //Use prefix increment
- {
- for(int y=0; y < max; ++y)
- {
- if( x + y == sum)
- {
- cout << sum << "\n"
- << x << "\n"
- << y << "\n"
- << diff << endl;
- if(abs(y - x) == diff)
- {
- cout << "\nSolutions are:" << "X=" << x << " " << "Y=" << y << endl;
- return 0;
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement