Swapping without using 3rd variable in c and c++ and any language use logic
Swapping without using third variable in c,c++,Java,JavaScript and any language logic....
// swapping without third variable.
#include<stdio.h>
#include<conio.h>
void main(){
int a,b;
clrscr();
printf("Enter the value of a=\t");
scanf("%d",&a);
printf("Enter the value of b=\t");
scanf("%d",&b);
printf("before swapping\n");
printf("a is=%d",a);
printf("\nb is=%d\n",b);
a=a+b;
b=a-b;
a=a-b;
printf("after swapping\n");
printf("a is=%d\n",a);
printf("b is=%d",b);
getch();
}
Divanshu Sindhwani
// swapping without third variable.
#include<stdio.h>
#include<conio.h>
void main(){
int a,b;
clrscr();
printf("Enter the value of a=\t");
scanf("%d",&a);
printf("Enter the value of b=\t");
scanf("%d",&b);
printf("before swapping\n");
printf("a is=%d",a);
printf("\nb is=%d\n",b);
a=a+b;
b=a-b;
a=a-b;
printf("after swapping\n");
printf("a is=%d\n",a);
printf("b is=%d",b);
getch();
}
Divanshu Sindhwani
Comments
Post a Comment