Swap two numbers without using third variable


Swap two numbers without using third variable

#include <stdio.h>
#include <conio.h>

void main()
{

int a=10;
int b=5;

clrscr();

printf("\nValues Before Interchange\n");

printf("\na is : %d",a);

printf("\nb is : %d",b);

a=a+b;

b=a-b;

a=a-b;

printf("\n\nValues After Interchange\n");

printf("\na is : %d",a);

printf("\nb is : %d",b);

getch();

}

Output :

0 comments:

Post a Comment