Sunday, October 25, 2009

6.PRGRM TO SWAP 2 NO. WITHOUT USING THIRD VARIABLE

//WAP TO SWAP TWO NO. WITHOUT USING THIRD VARIABLE
#include
#include

void main()
{
int x,y;
clrscr();
printf("Enter the First No.A=");
scanf("%d",&x);
printf("\n\nEnter the Second No.B=");
scanf("%d",&y);
printf("\n\n\n\nNo. Before Swaping");
printf("\nA=%d",x);
printf("\nB=%d",y);
x=x+y;
y=x-y;
x=x-y;
printf("\n\nAfter Swaping");
printf("\n\nFirst No.A=%d",x);
printf("\n\nSecond No.B=%d",y);
getch();
}
/******OUTPUT******
Enter the First No.A=4


Enter the Second No.B=9




No. Before Swaping
A=4
B=9

After Swaping

First No.A=9

Second No.B=4
*/

No comments:

Post a Comment

Programming the Whole World!