Saturday, 1 September 2012

Swapping without 3rd Variable

  • WAP to swap two number without using a third variable.

//WAP to enter two number and swap them.
#include <stdio.h>
#include <conio.h>
void main()
{
    int a,b;
    printf("Enter first numbers");
    scanf("%d",&a);
    printf("Enter second numbers");
    scanf("%d",&b);
    a=a+b-(b=a);
    printf("The first number after swapping is %d and second number is %d",a,b);
    }

No comments:

Post a Comment