Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int firstNum, secondNum, magicNum, combinations = 0;
- cin >> firstNum >> secondNum >> magicNum;
- bool isFound = false;
- for (int i = firstNum; i <= secondNum; i++) {
- for (int j = firstNum; j <= secondNum; j++) {
- combinations++;
- if (i + j == magicNum) {
- cout << "Combination N:" << combinations << " (" << i << " + " << j << " = " << magicNum << ")" << endl;
- isFound = true;
- break;
- }
- }
- if (isFound) {
- break;
- }
- }
- if (isFound == false) {
- cout << combinations << " combinations - neither equals " << magicNum << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement