Question: Can someone please help me with this coding/programming? I posted both files (swap.c and swaptest.c below) thank you!!! (swap.c) /* File : swap.c * *
Can someone please help me with this coding/programming?
I posted both files (swap.c and swaptest.c below) thank you!!!

(swap.c)
/* File : swap.c * * By : * * login: * * team : * * Date : */ /* * A function to swap floarting point values using pointers. */ #include#include "swap.h" #define DEBUG void swap( float *x, float *y) /* Given: pointers to two floating point variables Returns: nothing directly, swaps values at the two adresses given */ { float temp; #ifdef DEBUG printf("\tEntering sawp() with "); printf("\t\tx is address = %x, contents %f ", x, *x); printf("\t\ty is address = %x, contents %f ", y, *y); #endif /* save first value */ temp = *x; /* move second value to first */ *x = *y; /* restore first value to second */ *y = temp; #ifdef DEBUG printf("\tExiting sawp() with "); printf("\t\tx is address = %x, contents %f ", x, *x); printf("\t\ty is address = %x, contents %f ", y, *y); #endif }
(swaptest.c)
/* File : swaptest.c * * By : * * login: * * team : * * Date : */ /* * A test driver for testing the swap() function */ #include#include "swap.h" #define DEBUG int main() { float a = 2.5; float b = 5.9; float c = 12.3; #ifdef DEBUG printf("Initial values:\t a = %f, b = %f, c = %f ",a, b, c); #endif swap(&a, &b); #ifdef DEBUG printf("First swap:\t a = %f, b = %f, c = %f ",a, b, c); #endif swap(&b, &c); #ifdef DEBUG printf("Second swap:\t a = %f, b = %f, c = %f ",a, b, c); #endif swap(&a, &b); #ifdef DEBUG printf("Third swap:\t a = %f, b = %f, c = %f ",a, b, c); #endif }
Copy the files swap.c and swaptest.c to your directory. Create the appropriate header file, swap.h, for the function defined in swap.c. Compile this program using your makefile with the command: make swap Run the program and observe the output. Make sure you understand what this program is doing. It might help to draw a picture showing the trace of the code and state what the memory addresses are for the three variables, a, b, and c
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
