in C!!
12.12 LAB: Swapping variables
Write a program whose input is two integers and whose output is the two integers swapped.

Ex: If the input is:

3 8
then the output is:

8 3
Your program must define and call a function. SwapValues returns the two values in swapped order.
void SwapValues(int* userVal1, int* userVal2)

in C 1212 LAB Swapping variables Write a program whose input is two integers and whose output is the two integers swapped Ex If the input is 3 8 then the output class=

Respuesta :

tonb

Answer:

#include <stdio.h>

void SwapValues(int* userVal1, int* userVal2)

{

int temp = *userVal1;

*userVal1 = *userVal2;

*userVal2 = temp;

}

int main(void)

{

int a = 3;

int b = 8;

printf("Before swap: a=%d, b=%d\n", a, b);

SwapValues(&a, &b);

printf("After swap:  a=%d, b=%d\n", a, b);

return 0;

}

Explanation:

For swapping variables efficiently, you need a helper variable in C or C++.

Ver imagen tonb
ACCESS MORE