Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with these 2 question using UNIX The & operator can be used to quickly check if a number is odd or even.

I need help with these 2 question using UNIX

  1. The & operator can be used to quickly check if a number is odd or even. The value of expression (x & 1) would be non-zero only if x is odd, otherwise the value would be zero.

#include

int main()

{

//User enters an integer number

// if x is even, print even, otherwise print odd using & operator

return 0;

}

Complete the above program and test it with 17, 19, 22, 100.

Your output :

3.

Suppose two integer values a and b Perform, x = a ^ b Now x ^ b will evaluate to a and x ^ a will evaluate to b.

The following program is to swap two numbers using xor operator.

/**

* C program to swap two numbers using bitwise operator

*/

#include

int main()

{

int num1, num2;

/* Input two numbers from user */

printf("Enter any two numbers: ");

scanf("%d%d", &num1, &num2);

printf("Original value of num1 = %d ", num1);

printf("Original value of num2 = %d ", num2);

/* Swap two numbers */

//Fill out the codes using xor operator

printf("Num1 after swapping = %d ", num1);

printf("Num2 after swapping = %d ", num2);

return 0;

}

Output with test case: 66, 22

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Inductive Databases And Constraint Based Data Mining

Authors: Saso Dzeroski ,Bart Goethals ,Pance Panov

2010th Edition

1489982175, 978-1489982179

Students also viewed these Databases questions