C/Swap.c

23 lines
524 B
C

/* See https://git.disroot.org/oink/C for more details.
*
* Swap is a program that assigns a value to two variables,
* and swaps their values. Swap prints the values of each
* variable before and after their values are swapped.
*/
#include <stdio.h>
#include <stdlib.h>
int main() {
float a = 1.1, b = 2.2, temp; /* Example variables for swap */
printf("a = %.2f; b = %.2f\n", a, b); /* BEFORE */
/* Swap a and b */
temp = a;
a = b;
b = temp;
printf("a = %.2f; b = %.2f\n", a, b); /* AFTER */
return 0;
}