Kodewick
Start learning →
Starter→0 / 50

Swap two numbers

#001Startert = a; a = b; b = t;3 min

Swap the values in a and b: start with a = 3, b = 5, end with a = 5, b = 3. Finish swap_and_show(a, b) so it swaps the two values before showing them. The program swaps two pairs: 3 5 and -2 10.

Should show
5 3
10 -2
main.c
#include <stdio.h>

void swap_and_show(int a, int b) {
    int t;
    // your code here: use t to swap the values of a and b
    printf("%d %d\n", a, b);
}

int main(void) {
    swap_and_show(3, 5);
    swap_and_show(-2, 10);
    return 0;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.