Program to swap two numbers without using the third variable in C.

 

01 #include <stdio.h>
02 int main()
03 {
04
05 int a,b;
06
07 printf("enter number1: ie a");
08 scanf("%d",&a);
09 printf("enter number2:ie b ");
10 scanf("%d",&b);
11 printf("value of a and b before swapping is a=%d,b=%d",a,b);
12
13 a=a+b;
14 b=a-b;
15 a=a-b;
16
17 printf("value of a and b after swapping is a=%d,b=%d",a,b);
18
19 return 0;
20 }
 
 OUTPUT :

enter number1: ie a 12
enter number2: ie b 23

value of a and b before swapping is a=12,b=23
value of a and b after swapping is a=23,b=12

Related Post

Leave a Reply

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


The reCAPTCHA verification period has expired. Please reload the page.