Tuesday, 25 February 2014

'C' Code to swap 2 numbers without the use of a third variable




main()
{
int a,b;
printf("Enter the two numbers,namely 'a' and 'b'");
scanf("%d%d",&a,&b);
a = a + b;
b = a - b;
a = a - b;
printf("The swapped number 'a' is %d\n",a);
printf("The swapped number 'b' is %d\n",b);
}

No comments:

Post a Comment