swap without using third variable in c language

in c program , two variable value are swapping without using third variable in this program like a=10 and b=20 then a and b value are swap a=20 and b=10 without using third variable . In our c program to swap numbers we will not use a temp variable to swap two numbers .

Program :-

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <stdio.h>
#include <conio.h> 
void main()
{
   int a, b;
   clrscr();
 
   printf("Enter value of a = ");
   scanf("%d", &a);
   printf("Enter value of b = ");
   scanf("%d", &b);
 
   a = a + b;
   b = a - b;
   a = a - b;
 
   printf("a = %d\nb = %d\n",a,b);
   getch();
}

Example :-
Enter value of a = 10
Enter value of b = 20
a = 20
b = 10

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*