Tuesday, June 25, 2013

Write a program to Swap two no without using any third variable ?

Problem:
 Swap the 2 number without using any third variable .

Solution:

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

void main()
{
int a, b;
clrscr();
printf("\n enter the two no ");
scanf("%d%d",&a,&b);
printf("before swape \n A=%d   B=%d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\nafter swape \n A=%d   B=%d",a,b);
getch();
}


Output:


Like the Post? Do share with your Friends.

No comments:

Post a Comment