Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Swapping Two Numbers In C
WhatsApp
Shobana J
8y
3.7
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
C
Swapping
Up Next
Add Two Matrices In C
Ebook Download
View all
Printing in C# Made Easy
Read by 22.3k people
Download Now!
Learn
View all
Membership not found