C program to swap 2 numbers

// c program to swap 2 numbers using a temporary variable 
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,temp;
clrscr();
printf(“enter the first number\n”);
scanf(” %d”,&a);
printf(“enter the second number\n”);
scanf(“%d”,&b);
printf(” before swapping , numbers are %d and %d\n ” ,a,b);
temp =a;
a=b;
b= temp;
printf(“after swapping numbers are %d and %d\n”,a,b);
getch();
return 0;
}


// c program to swap 2 numbers without using a temporary variable
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b;
clrscr();
printf(“enter the first number\n”);
scanf(” %d”,&a);
printf(“enter the second number\n”);
scanf(“%d”,&b);
printf(” before swapping , numbers are %d and %d\n ” ,a,b);
a=a+b;
b=a-b;
a=a-b;
printf(“after swapping numbers are %d and %d\n”,a,b);
getch();
return 0;
}


C program to swap 2 numbers