TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Swapping Two Numbers In C
Shobana J
Jul 08, 2016
3.7
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
In this blog, you will learn how to swap two number in C.
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
Swapping
C
Next Recommended Reading
Add Two Matrices In C