Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an expression that is equivalent to x == y. It should evaluate to 1 if and

ID: 3879482 • Letter: W

Question

Write an expression that is equivalent to x == y. It should evaluate to 1 if and only if x and y are equal

"Expression" means that you should write simple code that doesn't involve looping. Use bitwise operators like AND (&), OR(|), NOT(~), XOR(^), shift left logical (<<), shift right logical (>>>), shift right arithmetic (>>).You should try to solve each of these problems on paper before writing the code.

public class Puzzles {

public static int Q1(int x) {

return 0;

}

}

Explanation / Answer

************C++ Program***********

Output = 1 if x and y are equal.

Else Output = 0.

#include<bits/stdc++.h>

using namespace std;


bool EqualNumber(int x, int y)   // function return true if x ^ y > 0 else false
{
return (x ^ y);
}


int main()
{
int x,y;
cout<<"Enter Two Numbers to be compared"<<endl;
cin>>x>>y;
cout<<"x = "<<x<<" y = "<<y<<endl;
cout << !EqualNumber(x, y) << endl;
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote