C LAB‎ > ‎(Sem1) Introduction to C‎ > ‎

WAP to swap two numbers without using another variable.

posted Dec 1, 2010, 8:25 PM by Neil Mathew   [ updated Dec 1, 2010, 8:48 PM ]
SOURCE CODE:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<stdio.h>
 
int main()
{
 
int a,b;
 
printf("\n Enter the value of A: ");
scanf("%d",&a);
 
printf(" Enter the value of B: ");
scanf("%d",&b);
 
//Swapping:
 
a=a+b;
b=a-b;
a=a-b;
 
printf("\n After Swapping... \n");
 
printf(" A: %d", a);
printf("\n B: %d", b);
 
return 0;
}


OUTPUT:

 Enter the value of A: 10
 Enter the value of B: 20

 After Swapping... 
 A: 20
 B: 10
Comments