Q:

Write a C++ program that accept two integers and return true if either one is 5 or their sum or difference is 5

0

Write a C++ program that accept two integers and return true if either one is 5 or their sum or difference is 5

Sample Output:

1
0
1

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
 
using namespace std;

bool test(int x, int y)
        {
            return x == 5 || y == 5 || x + y == 5 || abs(x - y) == 5;
        }
     
        
int main() 
 {
  cout << test(5, 4) << endl; 
  cout << test(4, 3) << endl; 
  cout << test(1, 4) << endl;     
  return 0;      
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now