Table of Contents
C program to swap two numbers without third variable
Following is the simple C program to swap two numbers without third variable.
Logic to swap two numbers without third variable in C
#include<stdio.h>
int main()
{
int x,y;
printf("Enter value for first(x) number : ");
scanf("%d",&x);
printf("Enter value for second(y) number : ");
scanf("%d",&y);
x=y+x;
y=x-y;
x=x-y;
printf("nValue of x after swapping : %d", x);
printf("nValue of y after swapping : %d", y);
return 0;
}
Output :
Enter value for first(x) number : 8
Enter value for second(y) number : 30
Value of x after swapping : 30
Value of y after swapping : 8
PRACTICALS/PRACTICE PROGRAM IN C
CHECKOUT OTHER RELATED TOPICS
CHECKOUT OTHER QUIZZES
Quizzes on Operator |
Easy Quiz on Operators in C part 1 |
Easy quiz on operators in C part 2 |
Easy quiz on operators in C part 3 |
Quizzes on Loops |
Easy quiz on loops in C part 1 |
Easy quiz on loops in C part 2 |
Easy quiz on loops in C part 3 |
Quizzes on Decision Making Statement |
Easy Quiz On Decision Making Statements Part 1 |
Easy Quiz On Decision Making Statements Part 2 |
Quizzes on String |
Easy quiz on String in C programming part 1 |
Quizzes on Array |
Easy quiz on Array in C programming – part 1 |
5 – Best Java program to convert decimal to binary |
New Quizzes Coming soon.. |
We are aiming to explain all concepts of C in easiest terms as possible.

ITVoyagers
Author