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.

advertisement:

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

 

#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

 

0 comments:

Post a Comment