subject

Program description: in this recitation assignment, will write a complete c program that accepts as input any two integers from the user and swaps both integers using bitwise operators only without a third variable. early on in your programming career, you were told that you need to use a third variable in order to swap two variables, but in this assignment, you will accomplish this task without the extra variable. we will use the bitwise xor operator to swap the integers as the bitwise xor operator evaluates each bit of the result to 1 if the corresponding bits of the operands are different and 0 otherwise. programming with c and unix optional reference textbook by adam hoover to be . your ta or fellow students although not required, you may find chapter 2 on bits, bytes, and data types in the system for this recitation assignment, complete the following tasks. you may receive guidance frorm 1. declare an integer pointer and then request memory using malloc () for an array of 2 integers. this means that you should request memory for a size of 2 times the size of an integer and assign it to int_ptr. use man 3 malloc for details on this system call 2. if the malloc ) system call failed to return memory, print out a meaningful error message and terminate the program 3. prompt the user to enter the first integer using printf and then read in the user's response using scanf, storing the integer in the first element of the integer array allocated in step 1. 4. prompt the user to enter the second integer using printf and then read in the user's response using scanf, storing the integer in the second element of the integer array allocated in step 1. 5. now, print out the original values of both the integers input by the user. 6. this next step is where the swapping is done: a. use the bitwise xor operator on both the array elements and assign the result to the first element. b. use the bitwise xor operator on both the array elements and assign the result to the second element. c. use the bitwise xor operator on both the array elements and assign the result to the first element. 7. now, print out the swapped values of both the integers input by the user. 8. finally, release the allocated memory using free () sample output (user input shown in bold): $ . /a. out enter first integer: 571 enter second integer: 18 original values: 1st 571 2nd18 swapped values: 1st- 18 2nd571 $ . /a. out enter first integer: -4 enter second integer: 288 original values: 1st -4 2nd288 swapped values: 1st 288 2nd - -4

ansver
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 04:30, justbepunky
There is a simple pattern for determining if a binary number is odd. what is it and why does this pattern occur? how many bits would you need if you wanted to have the ability to count up to 1000? how high could you count in binary if you used all 10 of your fingers as bits? (finger up means 1, finger down means 0)
Answers: 3
image
Computers and Technology, 22.06.2019 20:50, ashiteru123
What is the difference between windows 7 and windows 10?
Answers: 1
image
Computers and Technology, 23.06.2019 13:30, carolelai08
Stops: using the information learned in this course, explain three things you will not do when driving. a. b. c. explain why you will not do these things when driving. starts: using the information learned in this course, explain three things you will do when driving. a. b. c. explain why you will do these particular things when driving. explain one thing you will stop doing as a passenger. explain one thing you will start doing as a passenger.
Answers: 3
image
Computers and Technology, 24.06.2019 01:00, gymnast8900
Me if you do then you get 10 points and brainliest
Answers: 1
You know the right answer?
Program description: in this recitation assignment, will write a complete c program that accepts as...

Questions in other subjects:

Konu
Medicine, 05.03.2021 01:00