Sunday, 14 February 2016

C Program to Swap two numbers without third variable.

A Simple C Program to Swap two numbers without using another variable.


 #include<stdio.h>

int main() {
   int x,y;

   printf("Enter the value of X:");
   scanf("%d",&x);
    printf("\nEnter the value of Y:");
    scanf("%d",&y);
   x = x + y;
   y = x - y;
   x = x - y;

   printf("\nAfter swap value of X : %d", x);
   printf("\nAfter swapping value of Y : %d", y);

   return 0;
}

-----------------------------------------------------------------------------
Output:


 
For any question and help leave comments.......................

No comments:

Post a Comment