Home C C++ Java Python Perl PHP SQL JavaScript Linux Selenium QT Online Test

Home » Solved Programs » Program to swap two integer values

C program to swap two integer values

#include <stdio.h>

int main()
{
//declare three variables
int a, b, c;

printf("\n\nEnter the values of a : ");
scanf("%d",&a);
printf("\nEnter the values of b : ");
scanf("%d",&b);

printf("\nThe values before Swapping are \n");
printf("\n a : %d",a);
printf("\n b : %d",b);

//swapping logic
c = a;
a = b;
b = c;

printf("\n\n The values after Swapping are \n");
printf("\n a : %d",a);
printf("\n b : %d",b);

//hold the screen
getchar();

return 0;
}

Swapping of 4 & 5

C program to swap two integer values