SWAP WITHOUT USING THIRD VARIABLE

/*Swap without using third variable*/
#include<stdio.h>
#include<conio.h>
void main()
{
 int a,b,t;
 clrscr();
 printf("\n\tEnter Any First Number : ");
 scanf("%d",&a); //input
 printf("\n\tEnter Any Second Number : ");
 scanf("%d",&b); //input

 printf("\n\t**Before Swap**");
 printf("\n\ta = %d",a);
 printf("\n\tb = %d",b);

 a=a+b;
 b=a-b;
 a=a-b;

 printf("\n\t**After Swap**");
 printf("\n\ta = %d",a);
 printf("\n\tb = %d",b);

 getch();
}

Output

No comments:

Post a Comment

Programmingway@Eklavya Technosys!: Computer Solutions || Class-4 || Computer for Scho...

Programmingway@Eklavya Technosys!: Computer Solutions || Class-4 || Computer for Scho... :  1) Choose correct one :- 1) The step by step pla...