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

No comments


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


No comments :

Post a Comment