Swapping Two numbers in C with using a 3rd variable

#include <stdio.h>

int main(void) {
    double num1, num2;
    double temp; // 3rd variable
    printf("Enter the first number: ");
    scanf("%lf", &num1);
    printf("Enter the second number: ");
    scanf("%lf", &num2);
    printf("Before swapping the value of first number %.2lf \n and the value  of second number  %.2lf\n", num1, num2);

    // swapping logic
    temp = num1;
    num1 = num2;
    num2 = temp;

    printf("After swapping the value of first number %.2lf\nand the second number %.2lf\n", num1, num2);
    return 0;
}

Other videos in this series

Back To Home