How to Swap two numbers if they are not same?

CODE




Swap two numbers if they are not same
int main()
{
    int a,b;
    printf("\n enter the value of a and b:");
    scanf("%d%d",&a,&b);
    if(a!=b)
    {
        a=a+b;
        b=a-b;
        a=a-b;
        printf("\n after swaping:\n a=%d,b=%d",a,b);
    }
    else
    {
        printf("\n numbers are same");
    }
}


Output:
enter the value of a and b:
2
4

 after swaping:
 a=4,b=2

AND
enter the value of a and b:
2
2

 numbers are same

How to Swap two numbers if they are not same? How to Swap two numbers if they are not same? Reviewed by Unknown on December 14, 2018 Rating: 5

No comments:

If you have any doubt or query ,comment below:

Programming copyright © 2018-19. Powered by Blogger.