C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Trainings
Live
Learn
Career
Members
Blogs
Challenges
Certifications
Bounties
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Swapping Two Numbers In C
WhatsApp
Shobana J
9y
3.9
k
0
0
25
Blog
swap.zip
Introduction
In this article, I'm explaining how to swap two numbers in C.
Software Requirements
Turbo C++ OR C
Programming
#include <stdio.h>
int
main()
{
int
x, y, temp;
printf(
"Enter the value of x and y\n"
);
scanf(
"%d%d"
, &x, &y);
printf(
"Before Swapping\nx = %d\ny = %d\n"
,x,y);
temp = x;
x = y;
y = temp;
printf(
"After Swapping\nx = %d\ny = %d\n"
,x,y);
return
0;
}
Explanation
In the above program, before we swap the numbers, the values of x and y are in the correct order, as we have assigned them. After swapping, the numbers are interchanged.
Output
People also reading
Membership not found