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 18:30, dpinzoner5952
Which of the following commands is more recommended while creating a bot?
Answers: 1
image
Computers and Technology, 23.06.2019 12:30, umimgoingtofail
What is the difference between the internet and the world wide web?
Answers: 1
image
Computers and Technology, 24.06.2019 04:30, minecrafter3882
Fall protection, confined space entry procedures, controlled noise levels, and protection from chemical hazards are some of the things that contribute to a safe what
Answers: 1
image
Computers and Technology, 24.06.2019 05:30, kaylaamberd
Why is hard disk space important to an audio engineer? why are usb ports and firewire ports useful for an audio engineer? explain in 2-3 sentences. (3.0 points) here's a list of different audio software: ableton live apple inc.'s garageband apple inc.'s logic studio digidesign's pro tools propellerhead sofware's reason sony creative software's acid pro steinberg cubase steinberg nuendo choose one of the software programs listed above, and then go to that software program's web site. read about what the software program is used for, and then write 4-5 sentences about what you learned. (10.0 points) which type of software license is the most limiting? why? explain in 2-3 sentences. (3.0 points) when sending a midi channel voice message, how can you control the volume of the sound? explain in 2-3 sentences. (4.0 points)
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
Mathematics, 28.08.2019 09:50