Home / Programs / Program to show swap of two no's without using third variable
🚀 Programming Example

Program to show swap of two no's without using third variable

👁 1,522 Views
💻 Practical Program
📘 Step Learning
In this program we will show how to swap of two no's without using the third variable.

💻 Program Code

// Program to show swap of two no's without using third variable
// Author Atnyla Developer

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
 
printf("enter value for a & b: "); 
scanf("%d%d",&a,&b);
a = a+b;
b = a-b;
a = a-b;
printf("after swapping the value of a & b: %d %d \n",a,b);
 
}

                        

🖥 Program Output

<b>Output 1 </b>
enter value for a & b: 2  3
after swapping the value of a & b: 3 2
Press any key to continue . . .

<b>Output 2 </b>
enter value for a & b: 12
56
after swapping the value of a & b: 56 12
Press any key to continue . . .


                            

📘 Explanation

Program to show swap of two no's without using the third variable:
try this operation
a = a+b;
b = a-b;
a = a-b; <>
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.