Search This Blog

Monday, 3 March 2014

Swap two Number Without using third Variable or number

#include

int main()
{ int a,b;
printf("please enter first number:");
scanf("%d",&a);
printf("please enter Second number:");
scanf("%d",&b);
printf("\n\n");
printf("Number before swapping:\n");
printf("a=%d\n",a);
printf("b=%d\n",b);
//swap number
a=a+b;
b=a-b;
a=a-b;
printf("\n\n");//used for new line
printf("Number after swapping:\n");
printf("First Number a=%d\n",a);
printf("Second Number b=%d\n",b);
printf("\n\n");
   
    return 0;
    }

No comments:

Post a comment