Wednesday, 9 December 2015

C program: swapping of 2 numbers without using 3rd variable


#include<stdio.h>
int main(){
    int a,b,temp;
   
    printf("Enter any two integers: ");
    scanf("%d%d",&a,&b);
    printf("Before swapping: a = %d, b=%d",a,b);

    a=a+b;
    b=a-b;
    a=a-b;
    printf("After swapping: a = %d, b=%d",a,b);

    return 0;
}

No comments:

Post a Comment