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