Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- *******************************************************************************/
- #include <iostream>
- using namespace std;
- int main()
- {
- int a;
- int b;
- int c;
- int d;
- int res1;
- int res2;
- int res3;
- int operator1;
- int operator2;
- int operator3;
- int start;
- int endingVal;
- int counter;
- cin >> start;
- cin >> endingVal;
- for(a = 1; a <= 9; ++a){
- for(b = 1; b <= 9; ++b){
- for(c = 1; c <= 9; ++c){
- for(d = 1; d <= 9; ++d){
- for( operator1 = 1; operator1 <= 4; ++operator1 ){
- for(operator2 = 1; operator2 <= 4; ++operator2){
- for(operator3 = 1; operator3 <= 4; ++operator3){
- if (operator1 == 1){
- res1 = a + b;
- else if(operator1 == 2){
- res1 = a - b;
- else if(operator1 == 3){
- res1 = a / b;
- else if(operator1 == 4){
- res1 = a * b;
- }
- }
- }
- }
- if(operator2 == 1){
- res2 = res1 + c;
- }
- else if (operator2 == 2){
- res2 = res1 - c;
- }
- else if (operator2 == 3){
- res2 = res1 / c;
- }
- else if (operator2 == 4){
- res2 = res1 * c;
- }
- if (operator3 == 1){
- res3 = res2 + d;
- }
- else if(operator3 == 2){
- res3 = res2 - d;
- }
- else if(operator3 == 3){
- res3 = res2 / d;
- }
- else if(operator3 == 4){
- res3 = res2 * d;
- }
- if (res3 == 24){
- ++counter;
- if (counter >= start && counter <= endingVal){
- if (operator1 == 1){
- cout << a << " + " << b;
- }
- else if(operator1 == 2){
- cout << a << " - " << b;
- }
- else if(operator1 == 3){
- cout << a << " / " << b;
- }
- else if (operator1 == 4){
- cout << a << " * " << b;
- }
- if (operator2 == 1){
- cout << b << " + " << c;
- }
- else if (operator2 == 2){
- cout << b << " - " << c;
- }
- else if (operator2 == 3){
- cout << b << " / " << c;
- }
- else if (operator2 == 4){
- cout << b << " * " << c;
- }
- if(operator3 == 1){
- cout << c << " + " << d;
- }
- else if (operator3 == 2){
- cout << c << " - " << d;
- }
- else if(operator3 == 3){
- cout << c << " / " << d;
- }
- else if(operator3 == 4){
- cout << c << " * " << d;
- }
- cout << " = " << res3;
- cout << endl;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement