Swap two number without using third variable in c programming language.

For Example : 
a = 10;
b = 20;
a = 20;
b = 10;

Welcome guys..

We will be write the program in c how to swap two number without using third variable.

Let's start the code..

#include <stdio.h>

int main()
    int a, b;
    printf("Enter the value of a : ");
    scanf("%d", &a);
    printf("Enter the value of b : ");
    scanf("%d", &b);
    a = a + b;
    b = a - b;
    a = a - b;
    printf("The value of a is %d and b is %d", a, b);

    return 0;

Output :

Enter the value of a : 10
Enter the value of b : 20
The value of a is 20 and b is 10


Login is mandatory to comment Please login

Recommended Posts

Fibonacci Series | Fibonacci Series in C | @lapmos

Fibonacci numbers ( sequence ) is a set of numbers that start with 1 or 0 followed by a 1 proceeds on the rule that each number.

Palindrome | Palindrome program in c | Palindrome Number

Write a program in c to check that the given number is palindrome or not?

Pascal Triangle | C programming

pascal triangle program in c | Write a c program to print the pascal triangle.

Leap Year | Leap year program in c

Year is divisible by completely 4,100,400 then called that year is leap year.

Perfect Number in C Programming

What is Perfect Number? Perfect Number is a positive integer number that is equal to the sum of the its possible factors.
For Example : 6 is a Perfect Number

Strong Number in C programming | What is Strong Number

Strong Number is a number whose sum of the factorial of digits of number is equal to given number.
For Example : 145 is a strong number.