Computer Science, asked by justaigerim76, 21 days ago

(c++)Write a function bool check(int *a, int *b) that accepts integer a and b as pointers. The function returns true if either one is 6 or if their sum or difference is 6, otherwise it returns false.
1. 2 6 Yes
2. 4 10 Yes
3. -7 1 No

Answers

Answered by dreamrob
0

Program:

#include<iostream>

#include<math.h>

#include <iomanip>

using namespace std;

bool check(int *a, int *b)

{

if(*a==6 || *b==6 || (*a+*b)==6 || abs(*a-*b)==6)

{

 return true;

}

else  

{

 return false;

}

}

int main()

{

int a,b;

cout<<"Enter first number : ";

cin>>a;

cout<<"Enter second number : ";

cin>>b;

int *ptr1 = &a;

int *ptr2 = &b;

cout<<boolalpha;

cout<<check(ptr1 , ptr2);

return 0;

}

Output 1:

Enter first number : 2

Enter second number : 6

true

Output 2:

Enter first number : 4

Enter second number : 10

true

Output 3:

Enter first number : -7

Enter second number : 1

false

Similar questions