Write a program to swap two numbers without using a temporary variable.
C program mostly asked in interviews
#include<stdio.h>
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;
}
Output:
Enter values of a and b: 2 3
Before swapping a=2, b=3
The values after swapping are a=3 b=2
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment