C Program to Swap two Numbers without using third variable

C Program to Swap two Numbers without using third variable

The C Program to Swap any two Numbers without using third variable. It is clear that, we shuold have to give (assign) any two Numbers to two variable names as input, then the C program has to swap (exchange) the two numbers between the two variables. For example: If the two integer numbers are 37 and 78 assigned (stored) them into the variables x and y then, after swapping by the below given C program, x will have 78 and y will have 37. The below given C program will Swap any two Numbers without using third variable. Kindly check out the program to Swap any two Numbers without using third variable. The questions to Swap any two Numbers without using third variable can be asked as 

1). C Program to swap two numbers without using a temporary variable
2). C Program to Swap two numbers without using third variable
3). C program to swap two numbers
4). C program to swap two numbers using two variables
5). C program to swap two numbers by using two variables


Program to Swap any two Numbers without using third variable


    #include<stdio.h>
    int main(){
                  int x, y;
                  printf("Enter any two integer numbers : ");
                  scanf("%d %d", &x, &y);
                  printf("\n The value of x before swapping is %d", x);
                  printf("\n The value of y before swapping is %d", y);
                  x = x + y;
                  y = x - y;
                  x = x - y;
                  printf("\n The value of x after swapping is %d", x);
                  printf("\n The value of y after swapping is %d", y);
    return (0);
    }


Sample Output:

                  Enter any two integer numbers : 37   78
                  The value of x before swapping is 37
                  The value of y before swapping is 78
                  The value of x after swapping is 78
                  The value of y after swapping is 37


Related Popular Posts:

Other Related C Programs :


* C Program to find whether the given number is Odd or Even

* C Program to find the Sum of Odd Digits

* C Program to find the Sum of Even Digits

* C Program to find the Sum of Even and Odd Digits,

* C Program to Display Odd digits

* C Program to Display even digits

* C Program to Display Odd Numbers,

* C Program to Display Even Numbers,

* C Program to Check whether the given number is Armstrong number

* C Program to display the Armstrong numbers in Range

* C Program to display the Armstrong numbers between 1 and 1000

* C Program to check perfect number, perfect numbers in range

* C Program to Check Prime number, Prime numbers between 1 and 100

* C Program to display the Prime numbers in a Range

* C Program to display the Sum of Prime numbers

* C Program to Check Strong number

* C Program to display the Strong number in Range

* C Program to Check whether the given number is polindrome number or not

* C Program to Check polindrome number using for loop

* C Program to Check polindrome number using Recursion

* C Program to  check whether the given string is polindrome or not

* C Program to find the Roots of Quadratic equation

* C Program to display Fibonacci Series

* C Program to display the Fibonacci Series using an array

* C Program to display the Fibonacci Series using while loop

* C Program to find the Sum of Fibonacci Series, Factorial of Number

* C Program to find the Factorial without using Recursion

* C Program to find the Factorial using Pointers

* C Program to find the Factorial using Function

Bookmark and Share