Tuesday, 20 November 2012

How to swap two numbers without using third variable

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

void main()
{
int a,b;
clrscr();
printf("Enter the values of a and b");
scanf("%d%d",&a,&b);
a=b+a;
b=a-b;
a=a-b;
printf("After Swapping a=%d b=%d,a,b);
getch();
}

Output:
Enter the values of a and b
30 40
After Swapping a=40 b=30

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...