Enter your EMAIL address to get daily updates directly to your mail:

Do not forget to confirm the subscription by clicking the link sent in confirmation mail.


Saturday, 28 March 2015

// // Leave a Comment

Write a program to swap two numbers without using a temporary variable.


C program mostly asked in interviews


int main(){
int a, b;
printf("Enter values of a and b: \n");
scanf("%d %d",&a,&b);
printf("Be fore swapping a=%d, b=%d\n", a,b);
a = a + b;     
b = a - b;
a = a - b;
printf("Af ter swapping a=%d b=%d\n", a, b);
return 0;

Enter values of a and b: 2 3
Before swapping a=2, b=3
The values after swapping are a=3 b=2



Post a Comment