Write a C program to exchange two numbers without using temporary variable.

#include<stdio.h>

main()
{
    int a,b;
    printf("\nEnter two numbers=");
    scanf("%d%d",&a,&b);
    printf("\nBefore exchange a=%d,b=%d",a,b);
    a=a+b;
    b=a-b;
    a=a-b;
    printf("\nAfter exchange a=%d,b=%d",a,b);
}

No comments:

Post a Comment